At 19:34 09/03/2008, you wrote:
From: Ron Piggott <ron.php@xxxxxxxxxxxxxxxxxx>
Date: Sun, 09 Mar 2008 15:34:05 -0400
Message-Id: <1205091245.16466.1.camel@xxxxxxxxxxxxxxxxxxxxx>
What is the correct syntax for where the results may be 1 or 2? What
have I done wrong?
SELECT * FROM table WHERE name LIKE "ABC" AND listing_type = 1 or 2
C'mon Ron, this is basic SQL. The query you provided would have given
all rows where name was like 'abc', listing type was 1, then returned
all rows because `OR 2` results in a value of 'true' which matches
everything (you could also have written OR 2 = 2 with the same effect)
SELECT * FROM table WHERE name LIKE "ABC" AND (listing_type = 1 OR
listing_type = 2);
SELECT * FROM table WHERE name LIKE "ABC" AND listing_type IN (1, 2);
Now I've spoon fed you, please read the manual on "Operator
Precedence" which explains how to combine stuff like this so you
don't get the "wrong" result
http://dev.mysql.com/doc/refman/5.0/en/operator-precedence.html : "To
override this order and group terms explicitly, use parentheses"
(first query above)
Cheers - Neil
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php