aadu
aadu

Reputation: 3254

MySQL SELECT WHERE EQUALS syntax

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

When I use this query:

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

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

Upvotes: 5

Views: 22965

Answers (2)

Abdul Rahman Sabbagh
Abdul Rahman Sabbagh

Reputation: 31

You should look at the statement after the WHERE as a boolean statement on its own. I mean, your expression should look like this:

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

Upvotes: 1

David M
David M

Reputation: 72890

You need to use WHERE idParticipant IN (118, 119);

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.

Upvotes: 8

Related Questions