PDA

View Full Version : how do 'does not equal' in mySQL?


Bobafart
02-01-2008, 03:23 PM
simple question, cant find the answer

the error is at the end "WHERE id != 1037"

all give errors:


SELECT id, headline, permalink, body, favico, author FROM anews_2_08 WHERE headline LIKE '% health %' OR headline LIKE '% war %' OR headline LIKE '% care %' OR headline LIKE '% clinton %' OR headline LIKE '% obama %' and WHERE NOT id = 1037 GROUP BY headline ORDER BY dateUnix DESC LIMIT 5



SELECT id, headline, permalink, body, favico, author FROM anews_2_08 WHERE headline LIKE '% health %' OR headline LIKE '% war %' OR headline LIKE '% care %' OR headline LIKE '% clinton %' OR headline LIKE '% obama %' and WHERE id != 1037 GROUP BY headline ORDER BY dateUnix DESC LIMIT 5



SELECT id, headline, permalink, body, favico, author FROM anews_2_08 WHERE headline LIKE '% health %' OR headline LIKE '% war %' OR headline LIKE '% care %' OR headline LIKE '% clinton %' OR headline LIKE '% obama %' and WHERE id <> 1037 GROUP BY headline ORDER BY dateUnix DESC LIMIT 5

mySQL doesn't like my variations on WHERE id <> 1037 as this is where the error occurs.

I even confirmed these variations in a google search.. so I must be doing something else incorrect

Bobafart
02-01-2008, 04:10 PM
dumb me

please ignore

i used WHERE twice in my select


silly me.. need more sleep

Andrew Johnson
02-06-2008, 11:15 PM
3 options:

SELECT * FROM table WHERE col <> val

SELECT * FROM table WHERE col != val

SELECT * FROM table WHERE NOT col =val

oops, just saw that you noticed a typo - I'll post anyways for reference purposes

StupidRalph
02-06-2008, 11:29 PM
I just wanted to note that:
% text % != %text% /* the first requires a preceding and trailing space while the second one does not*/
I think you'll be safe for what you're doing I just wanted to chime in.