Click to See Complete Forum and Search --> : WHERE question


psicloone
07-03-2009, 08:55 PM
I have table which have column "username" and I want to select multiple values after WHERE, but I can`t find anywhere in google the right synthax. I want to do something like:


SELECT * FROM messages WHERE username = 'aaa' , "john", "mike"

Reis
07-03-2009, 09:44 PM
u can do:

SELECT * FROM messages WHERE username = 'aaa' AND username = "john" AND username = "mike"

or u can do

SELECT * FROM messages WHERE username = 'aaa' OR username = "john" OR username = "mike"

psicloone
07-04-2009, 05:37 AM
u can do:

SELECT * FROM messages WHERE username = 'aaa' AND username = "john" AND username = "mike"

or u can do

SELECT * FROM messages WHERE username = 'aaa' OR username = "john" OR username = "mike"

Oooo, I tried that but it didn`t work, that`s why I`m posting the thread

"MySQL returned an empty result set (i.e. zero rows). ( Query took 0.0004 sec )"

Malgrim
07-04-2009, 05:47 AM
The most common approach would be:
SELECT * FROM messages WHERE username IN ('aaa','john','mike');

but this should work too:
SELECT * FROM messages WHERE username = 'aaa' OR username = 'john' OR username = 'mike';

That will certainly return an empty set:
SELECT * FROM messages WHERE username = 'aaa' AND username = "john" AND username = "mike"

psicloone
07-04-2009, 05:56 AM
Thanks, that did work :)