I have to select all the records where FIELD1 is value11 or value12 and FIELD2 is value21, value22, value23, ... or value29. All 2*9=18 pairs of admissible values for FIELD1 and FIELD2 are possible. Which is the most compact form to write down my SQL query?
+3
A:
where field1 in (value11, value12) and field2 in (value21, value22, value23, ..., value29)
(Where you need to replace the dots with all value24
and so on.)
Arjan
2010-10-14 17:28:00
@Arjan: `BETWEEN` is another option. `[...] WHERE [...] FIELD2 BETWEEN VALUE21 AND VALUE29`
Sathya
2010-10-14 17:39:04
@Sathya, that would be true if the values are really subsequent. (I understood they are database columns themselves?)
Arjan
2010-10-14 17:40:32
(That's too soon of an accepted answer for trying to find the most compact form!)
Arjan
2010-10-14 17:41:05
Thanks for your prompt reply. I have updated my question since I have recognized that my situation is a bit more complex. So, please see http://superuser.com/questions/199517/and-or-like-conditions-in-a-sql-query
2010-10-14 17:41:58
@Arjan Indeed, that's why I mentioned as a supplementary comment.
Sathya
2010-10-14 17:45:32