Forum Moderators: coopster
SELECT * FROM mytable_items AS i LEFT JOIN mytable_types AS t ON i.type_id=t.type_id WHERE i.item_flag='1' OR i.item_flag='0' AND i.item_visible='1' AND i.type='test' ORDER BY i.type_id ASC, i.item_cost ASC
What it should do is pull all visible items of the type 'test', and `item_flag` of 1 or 0. What its doing is getting items with a flag of 1 and then optionally ignoring the rest of the conditions because I said 'OR'.
What I think I would like to do is to somehow encapsulate the OR to only affect the item_flag fields... in php I would write it with brackets, but I'm not sure of the right syntax to use with an SQL statement. If I was writing it in php I would probably want it something like this:
if (($item_flag==0 ¦¦ $item_flag ==1) && $item_visible==1 && $type=='test')
Hope I'm making sense. Can anyone tell me the correct syntax to use to help compartmentalise the WHERE clause logic? (It's probably something as simple as brackets, but I haven't found the answer yet).