MySQL SELECT WHERE EQUALS 语法

问题描述:

我有一个名为 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.