Click to See Complete Forum and Search --> : Selecting Rows with two `where` statements


Kyleva2204
07-03-2006, 09:18 PM
Hello, I am wondering if it is possible to select rows where, the where statement includes two of the same operator or something.. Im no good at explaning but this would be the best way to show you what I mean:

SELECT DISTINCT `USER_ID2` WHERE `USER_ID` = '1' AND `USER_ID` = '4';

and that would show all the fields where the user_id = 1 and 4... :-\

thanks in advanced.

themarty
07-03-2006, 09:25 PM
and that would show all the fields where the user_id = 1 and 4... :-\
That's impossible. If the user_id = 1 it cannot be 4 (because it's 1)

i guess you mean

SELECT DISTINCT `USER_ID2` WHERE `USER_ID` = '1' OR `USER_ID` = '4';

Kyleva2204
07-03-2006, 09:30 PM
well, I want it to seelct them both, and display both of them,

aussie girl
07-03-2006, 10:04 PM
As long and USER_ID2 is a column name, it should work

SELECT DISTINCT(USER_ID2), columnname,columname FROM tablename
WHERE USER_ID` = '1' AND USER_ID = '4';

Kyleva2204
07-03-2006, 10:10 PM
it doesn't return any rows.. the actual code is:

SELECT * FROM `friends` WHERE `user_id` = '1' AND `user_id` = '4'

felgall
07-03-2006, 11:07 PM
user_id will never be equal to 4 when it is equal to 1 and never equal to 1 when it is equal to 4 since a single field can only have one value at a time. You probably mean OR rather than AND as using OR will return records where it is equal to 1 as well as records where it is equal to 4.

SELECT * FROM `friends` WHERE `user_id` = '1' OR `user_id` = '4

Kyleva2204
07-03-2006, 11:09 PM
but, it didnt for me.. :\

-- edit --
NVM.. my bad thanks :)