Forum Moderators: coopster
I have a query of the following format. I'm using * for simplicity here, I'm only selecting 5 fields...
SELECT * FROM mytable WHERE
field1 = 'x' and field2 = 'y' and field3 = 'a'
OR
field1 = 'x' and field2 = 'y' and field3 = 'b'
OR
field1 = 'x' and field2 = 'y' and field3 = 'c'
Should there not be some way that I can write this in a - for lack of a better description - more 'compunded' format?
Do I have to write the "field1 = 'x' and field2 = 'y'" part each and every time? In some instances there can be up to 50 different values for field3, and the query gets a bit wordy...
The query itself is automatically generated, so perhaps this isn't so important, or is it? Does the size of the query matter, or is it okay as long as it gets the job done ;-]?
$values = "'a','b','c'";This works well when you want to build that list dynamically.
$query = "SELECT * FROM mytable WHERE
field1 = 'x' and field2 = 'y' AND field3 IN($values)";