By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,958 Members | 1,179 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,958 IT Pros & Developers. It's quick & easy.

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

P: 229
I wonder if anyone can tell me how to write this query properly as this one doesnt work.

where'Abstract' and'Abstract art'

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

Thanks in advance
Aug 17 '10 #1
Share this Question
Share on Google+
4 Replies

Expert 100+
P: 145
This is kind of a data questions. I think the syntax you're looking for is OR.

Expand|Select|Wrap|Line Numbers
  1.'Abstract' OR'Abstract art'
Aug 18 '10 #2

Expert 2.5K+
P: 3,405
Expand|Select|Wrap|Line Numbers
  1. in ('Abstract','Abstract art','Modern art')
Aug 25 '10 #3

Expert Mod 15k+
P: 31,662
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

Expert 2.5K+
P: 2,878
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.