xXREDXIIIXx Posted May 3, 2010 Share Posted May 3, 2010 Here's my query but The OR is making the != '6' invalid want to be able to include both genres on the 'games page' but obviously not show the same game in the related section SELECT gameid, title FROM games WHERE gameid != '6' AND gen1 = 'First Person Shooter' OR gen2 = 'Online' ORDER BY RAND( ) LIMIT 5 3 Battlefield: Bad Company 4 Battlefield: Bad Company 2 8 Crysis 2 7 Call of Duty 4: Modern Warfare 6 Call of Duty: Modern Warfare 2 <-- This ID should not be included Quote Link to comment https://forums.phpfreaks.com/topic/200595-exclude-1-id-from-sql-query-while-using-an-or/ Share on other sites More sharing options...
Mchl Posted May 3, 2010 Share Posted May 3, 2010 Does 2 * 3 + 4 = 2 * (3 + 4) ? Quote Link to comment https://forums.phpfreaks.com/topic/200595-exclude-1-id-from-sql-query-while-using-an-or/#findComment-1052620 Share on other sites More sharing options...
xXREDXIIIXx Posted May 3, 2010 Author Share Posted May 3, 2010 Does 2 * 3 + 4 = 2 * (3 + 4) ? 10 / 14 ?? so no...? Quote Link to comment https://forums.phpfreaks.com/topic/200595-exclude-1-id-from-sql-query-while-using-an-or/#findComment-1052622 Share on other sites More sharing options...
Mchl Posted May 3, 2010 Share Posted May 3, 2010 Same for logic operators. AND is like * and OR is like + gameid != '6' AND ( gen1 = 'First Person Shooter' OR gen2 = 'Online' ) Quote Link to comment https://forums.phpfreaks.com/topic/200595-exclude-1-id-from-sql-query-while-using-an-or/#findComment-1052654 Share on other sites More sharing options...
xXREDXIIIXx Posted May 3, 2010 Author Share Posted May 3, 2010 thanks never was any good at math. Quote Link to comment https://forums.phpfreaks.com/topic/200595-exclude-1-id-from-sql-query-while-using-an-or/#findComment-1052659 Share on other sites More sharing options...
Muddy_Funster Posted May 3, 2010 Share Posted May 3, 2010 Basicly, and rightly, he's saying to use brackets: SELECT gameid, title FROM games WHERE ((gameid != '6' AND gen1 = 'First Person Shooter') OR (gameid != '6' AND gen2 = 'Online')) ORDER BY RAND( ) LIMIT 5 Should do what you want it to. In the future I would recomend that if you are making any multi-part where clause just bracket it up (you can even put brackets round a single WHERE (a = b) if you fancy it. Quote Link to comment https://forums.phpfreaks.com/topic/200595-exclude-1-id-from-sql-query-while-using-an-or/#findComment-1052664 Share on other sites More sharing options...
Mchl Posted May 3, 2010 Share Posted May 3, 2010 Basicly, and rightly, he's saying to use brackets: SELECT gameid, title FROM games WHERE ((gameid != '6' AND gen1 = 'First Person Shooter') OR (gameid != '6' AND gen2 = 'Online')) ORDER BY RAND( ) LIMIT 5 Actually your example would not require brackets any more. It's equivalent to: 2 * (3 + 4) = 2 * 3 + 2 * 4 Quote Link to comment https://forums.phpfreaks.com/topic/200595-exclude-1-id-from-sql-query-while-using-an-or/#findComment-1052669 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.