Page 1 of 1

MySQL query problem

Posted: Tue Jul 20, 2004 6:06 am
by Xelmepa
Hello,

I'm having a problem with this MySQL query.

While this works great:
їcode]
SELECT * FROM table WHERE field2='animal'
ї/code]

The following is accepted as a query, but returns no results:

їcode]
SELECT * FROM table WHERE 'key'=3
ї/code]

The values I gave are random, but of the same nature as in reality.

field2 is a VARCHAR field, nothing special about it
key is PRIMARY KEY and has the auto_increment extra.

The question is, why doesn't it return any results?
In the database there are about 8 entries, so key does reach the value I gave it... Any ideas?

PS: I had to use 'key'=3 and not key=3 because (obviously) KEY is part of the SQL syntax or something.

Posted: Tue Jul 20, 2004 8:14 am
by liljester
by putting key in single quotes you are making it a value instead of a field name.. 'key' will never equal 3... if it reserved word use backquotes.. (the key to the left of the number 1)

Code: Select all

SELECT * FROM table WHERE `key` = 3

Posted: Tue Jul 20, 2004 3:29 pm
by Xelmepa
Thank you!

It worked fine.