MySQL SELECT WHERE EQUALS 语法 [英] MySQL SELECT WHERE EQUALS syntax

查看:33
本文介绍了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.

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆