dujmovicv — 2010-05-18T12:55:39-04:00 — #1
I was wondering if it's possible to set multiple conditions in a query like :
SELECT * FROM contacts WHERE asker_id = '$user_ID' OR receiver_id = '$user_ID' AND status = 1
My goal is to find out how many CONFIRMED (status = 1) connections a user with the given ID has...
Hope someone can help....
dujmovicv — 2010-05-18T13:08:23-04:00 — #2
Thank you guys! That's exactly what I needed!
By the way, I agree with r937....
Have a nice day!
r937 — 2010-05-18T13:04:12-04:00 — #3
i hate that default mysql colour coding
those lime green parentheses are practically invisible, and they're the most important part of the statement
guido2004 — 2010-05-18T13:01:27-04:00 — #4
Yes, it's possible. But once you're using AND and OR in one query, you'll have to tell MySQL the order of things (using parentheses):
WHERE (asker_id = '$user_ID' OR receiver_id = '$user_ID')
AND status = 1
If you don't use ( and ), then the outcome might not be what you expect
r937 — 2010-05-18T13:01:07-04:00 — #5
yes, that's possible
although you will want to use parentheses when you are mixing ANDs and ORs
these two are fundamentally different --
WHERE ( asker_id = '$user_ID' OR receiver_id = '$user_ID' ) AND status = 1
WHERE asker_id = '$user_ID' OR ( receiver_id = '$user_ID' AND status = 1 )
if you leave out the parentheses, it's the same as the second one