View Full Version : multiple WHERE
what is the correct syntax for multiple WHERE statements
SELECT * FROM mytable
WHERE color_type=bw and WHERE type=editorial
thanks!!!!
You only need one WHERE and you need to wrap values in quotation marks
SELECT * FROM mytable
WHERE color_type='bw' and type='editorial';
thanks .. and where you do an or is it like this
SELECT * FROM mytable
WHERE color_type='bw || color || paint' and type='editorial';
or is it like this
SELECT * FROM mytable
WHERE color_type='bw' || 'color' || 'paint' and type='editorial';
You only need one WHERE and you need to wrap values in quotation marks
SELECT * FROM mytable
WHERE color_type='bw' and type='editorial';
one thing I forgot to mention is that I want to write the sql statement so both things are required so for
SELECT * FROM mytable
WHERE color_type='bw' and type='editorial';
I want only the records that have the color_type bw and are also the type editoral ..
is this still the correct way to write that?
yea, that's right
SELECT * FROM table WHERE (this = 1 AND this = 2) OR (this =3 AND this=4) OR this=5 ORDER BY that ASC
That is, to the best of my knowledge, a valid select statement.
RTH10260
7-10-05, 04:55 AM
thanks .. and where you do an or is it like this
SELECT * FROM mytable
WHERE color_type='bw || color || paint' and type='editorial';this is not what you are looking for, here you are asking that field color_type contains that full string as content.
or is it like this
SELECT * FROM mytable
WHERE color_type='bw' || 'color' || 'paint' and type='editorial';Yes, it's more like this, just be sure to add sufficient parantheses to make operator precedence clear (one stumbles otherwise over the definition). Then you cannot use an abbreviation like this, you must either write out the three terms, or use the IN operator:SELECT * FROM mytable
WHERE (color_type='bw' || color_type='color' || color_type='paint')
and type='editorial';orSELECT * FROM mytable
WHERE color_type IN ('bw','color','paint') and type='editorial';
(syntax not checked, may contain minor error)
thanks guys .. this works awesome!
vBulletin v3.6.0, Copyright ©2000-2009, Jelsoft Enterprises Ltd.