[SOLVED] MySQL query problem

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
User avatar
Xelmepa
Forum Commoner
Posts: 41
Joined: Sat Aug 24, 2002 3:02 pm
Location: Athens, Greece
Contact:

MySQL query problem

Post 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.
User avatar
liljester
Forum Contributor
Posts: 400
Joined: Tue May 20, 2003 4:49 pm

Post 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
User avatar
Xelmepa
Forum Commoner
Posts: 41
Joined: Sat Aug 24, 2002 3:02 pm
Location: Athens, Greece
Contact:

Post by Xelmepa »

Thank you!

It worked fine.
Post Reply