MySQL SELECT WHERE EQUALS 语法

编程入门 行业动态 更新时间:2024-10-22 07:39:37
本文介绍了MySQL SELECT WHERE EQUALS 语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我有一个名为 Participant 的 MySQL 数据库表,它看起来像这样:

I have a MySQL database table called Participant that looks something like this:

(idParticipant) - (firstName) - (secondName) - (gender) - (dob)

118   John     Dunne         m    1944-04-01

117   Mary     Delaney       f    1955-05-03

116   Adam     Bermingham    m    1920-01-01

115   Eamonn   Reilly        m    1987-03-19

114   Aaron    Duane         m    1990-07-08

119   Sarah    Calvin        f    1977-07-17

当我使用这个查询时:

SELECT * FROM `Participant` WHERE idParticipant = 118 OR 119;

我想我应该得到以下结果:

I think I should get the following result:

118  John    Dunne       m    1944-04-01

119  Sarah   Calvin      f    1977-07-17

但它只是返回整个表.我的 MySQL 语法哪里出错了?

But instead it just returns the whole table. Where am I going wrong in my MySQL syntax?

推荐答案

你需要使用WHERE idParticipant IN (118, 119);

我的猜测是 MySQL 将 119 的值隐式转换为布尔真值,所以您说:WHERE idParticipant = 118 OR TRUE;,从而包括所有行.首先计算相等性,然后是布尔 OR.

My guess is that MySQL is implicitly converting the value of 119 to a Boolean true value, so you are saying: WHERE idParticipant = 118 OR TRUE;, thus including all the rows. The equality is evaluated first, followed by the Boolean OR.

这篇关于MySQL SELECT WHERE EQUALS 语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-05-01 13:26:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1410156.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:语法   MySQL   SELECT   EQUALS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!