You AND's limit the query - what you have there would only accept: a equal to b, AND at least one of b,c, or d must equal to $var1 AND with b not equal to 99, So a=1 and b=1 and $var1 = 1 would work, but a=1 and b,c,d=1 and $var1 = 2 wouldn't. If you want the 'or none' factor, just drop the entire $var1 line - that will give you a=b and b!=99. If you're trying to get it to be an exclusive match, e.g. if b=$var1 then c and d can't - you need to spell it out with XOR (exclusive-or's) 'A XOR B' is true if A evaluates to true or B evaluates to true - but not both. (but for a search, I doubt you want it XOR'd - no?) ----- You might want to be using LIKE instead of = if there should be substrings. http://dev.mysql.com/doc/mysql/en/SELECT.html (assuming mysql, though it should be fairly vanilla SQL anyway) - Martin Norland, Database / Web Developer, International Outreach x3257 The opinion(s) contained within this email do not necessarily represent those of St. Jude Children's Research Hospital. -----Original Message----- From: Carlos Alberto Bazan-Canabal [mailto:carlos.bazan@xxxxxxxxx] Sent: Thursday, October 21, 2004 2:26 PM To: php-db@xxxxxxxxxxxxx Subject: Organizing a query Hello. I'm working on a simple search for my file, and I have a question on structuring my query. This is what I want to do: select * from table where a=b AND (b=$var1 or c=$var1 or d=$var1) AND b <> 99 In the above, you could have: - either b or c or d or none would = $var1 - more than one of b or c or d would = $var1 Could anyone suggest a syntax for my select statement? Thank you! Carlos. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php