query IS NULL error

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Doshaburi
Forum Newbie
Posts: 2
Joined: Wed Feb 11, 2009 12:04 pm

query IS NULL error

Post by Doshaburi »

Hello,

I have this piece of code:

Code: Select all

foreach(range("a","z") as $letter){
    $result = mysql_query("SELECT * FROM mails WHERE mail LIKE '{$letter}%' AND group IS NULL") or die("ERROR:".mysql_error());
}
And when i try to run the script it outputs this:

ERROR:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'group IS NULL' at line 1

The 'group' field is a varchar type and is set to NULL by default.

What could be the couse of this error?

Without the "AND group IS NULL" it works fine btw.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: query IS NULL error

Post by Eran »

group is a reserved word in mysql. You'd be better off changing the column name to something else, or you can quote the column name using backhand ticks:

Code: Select all

SELECT * FROM mails WHERE mail LIKE 'a%' AND `group` IS NULL
Last edited by Eran on Wed Feb 11, 2009 12:32 pm, edited 1 time in total.
Doshaburi
Forum Newbie
Posts: 2
Joined: Wed Feb 11, 2009 12:04 pm

Re: query IS NULL error

Post by Doshaburi »

thnx mate it worked like a charm :)
Post Reply