Jump to content

Recommended Posts

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

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.

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

 

;)

 

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.