PDA

View Full Version : Help me sort out some logical operators in a MYSQL query



hondaworkshop
01-20-2007, 05:26 PM
Here's my general query layout for helping users wheedle down database rows to what they are looking for:


SELECT from `mytable` WHERE `category`='wheels' AND `subcategory`='15 inch' AND(`title` LIKE '%konig%' OR `title` LIKE '%rota%' )

I want it to meet a few REQUIRED conditions, AND meet at least ONE of my multiple OR-separated conditions. What is the correct syntax for this query?

Pethens
01-20-2007, 08:15 PM
The conditions you are using will work. The only problem is that you're not selecting any columns. Try this:


SELECT * from mytable WHERE category='wheels' AND subcategory='15 inch' AND (title LIKE '%konig%' OR title LIKE '%rota%' )

That query should work if all the columns and tables it uses exist.

Stephen

hondaworkshop
01-20-2007, 10:04 PM
That was my typo in the post, but not really verbatim of my code.

For some reason AND(...OR...) doesnt work, but I've found that it DOES work if I put the (...OR...) part at the very beginning of the query string after WHERE...and that's good enough for me.