PDA

View Full Version : Is anything wrong with this query?



Christopher
June 11th, 2002, 17:57
SELECT * FROM content WHERE for='NEWS' ORDER BY id DESC LIMIT 3

Says there is a parse error on line 13... Whole line:


$get_news = mysql_query("SELECT * FROM content WHERE for='NEWS' ORDER BY id DESC LIMIT 3")) or die(errorMsg());

Christopher
June 11th, 2002, 17:58
Nevermind, just got it...

I put an extra ")" at the end...

Christopher
June 11th, 2002, 18:01
Arg, the parse error is gone, but there is something wrong with the query... Help?

Dusty
June 11th, 2002, 18:30
"For" is a MySQL reserved word, you can't use it without quoting.

SELECT * FROM `content` WHERE `for` LIKE 'NEWS' ORDER BY `id` DESC LIMIT 3

Christopher
June 11th, 2002, 18:35
Originally posted by Dusty
"For" is a MySQL reserved word, you can't use it without quoting.

SELECT * FROM `content` WHERE `for` LIKE 'NEWS' ORDER BY `id` DESC LIMIT 3
Ahh... Well, I think I'll just rename the for to something else, easier...

And to do the condition, you have to do "LIKE 'NEWS'" ? Or is my
"='NEWS'" alright?

EDIT Nevermind, works like a charm! Thanx again Dusty.

Dusty
June 11th, 2002, 18:43
= will work to for that, too. If ever you use % or _ in your matching, though, you'd have to use LIKE.

Christopher
June 11th, 2002, 19:00
lol, one last question...

How do you return results where a column is NULL?

I tried " WHERE pid='' " (empty single quotes) but it didn't work...

Dusty
June 11th, 2002, 19:06
pid=NULL

Christopher
June 11th, 2002, 20:14
Well, that didn't work. So I took it upon myself to go out on the big web and find the answer because I didn't want to look like an idiot coming here asking question after question.

Observations: Do not use pid=NULL, you use pid IS NULL.

Hehe, I did it all on my own!

:p :biggrin2: :D