469,950 Members | 1,938 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,950 developers. It's quick & easy.

How to query the same table for more than one possible results

229 100+
Hi,
I wonder if anyone can tell me how to write this query properly as this one doesnt work.

where tbl.gallery='Abstract' and tbl.gallery='Abstract art'

Need to query the same table for the results that match the two possible results.

Thanks in advance
Richard
Aug 17 '10 #1
4 1277
Jerry Winston
145 Expert 100+
This is kind of a data questions. I think the syntax you're looking for is OR.

Expand|Select|Wrap|Line Numbers
  1. tbl.gallery='Abstract' OR tbl.gallery='Abstract art'
Aug 18 '10 #2
jhardman
3,406 Expert 2GB
alternatively,
Expand|Select|Wrap|Line Numbers
  1. tbl.gallery in ('Abstract','Abstract art','Modern art')
Jared
Aug 25 '10 #3
NeoPa
32,233 Expert Mod 16PB
What you have to understand Richard, is that an AND in the WHERE clause is not saying :
Expand|Select|Wrap|Line Numbers
  1. Get me :
  2. All records where {first check}
  3. AS WELL AS 
  4. All records where {second check}
Rather, it is saying :
Expand|Select|Wrap|Line Numbers
  1. Get me all records where {first check} AS WELL AS {second check}
Thus, records are only selected when both checks succeed.

You need to use the OR conjunction instead as has already been said by Jerry.

For more flexibility use the IN() function (as per Jared's post). Two checks is fine with OR but going beyond that is better with IN().
Aug 25 '10 #4
ck9663
2,878 Expert 2GB
I'll throw a wrench :)...

If you're using an OR in any of your condition, place the most probable TRUE condition first. If you're using an AND, place the most probable FALSE condition first.

This way, a complicated condition need not be test throughout. In OR, only one of the condition needs to be TRUE to make the entire condition as TRUE. In an AND, only one condition needs to be FALSE to make the entire condition as FALSE.

Although it's not always 100% that the server will parse the condition from left to write, it usually do.

Happy Coding!!!

~~ CK
Aug 25 '10 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

By using this site, you agree to our Privacy Policy and Terms of Use.