• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Very simple Mysql select query, why is it failing?

Red Squirrel

No Lifer
I'm trying this query:

Code:
SELECT kid, kdata FROM keys WHERE kuser='1'

And it keeps failing with this error:

Code:
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 'keys WHERE kuser=1' at line 1

I don't get it, what is wrong with the query? I tried with and without the single quotes.

The table structure is rather basic too. kid is an int, kdada is text and kuser is int. Am I going crazy here or does this query has a typo that I'm just missing?
 
Ok renamed table and now it's ok. I always forget that there's certain words that mysql does not like if you use for names of rows or tables. Wish it would actually tell you that instead of just saying there's a syntax error.
 
No SQL I've used has good error messages. I'm surprised it let you name the table keys.

That's the thing, if it's a reserved keyword you'd think it would have just not let me name it that in first place! Seems like a design fail. Funny enough I always add some kind of prefix to column names to prevent this but never really thought of doing it for table names. There's odd ball names that just seem to cause all sorts of weird issues. I'm sure there's a list of them somewhere but not really something I would remember to check every time.
 
it is always a good habit to use quotes and ticks in your SQL statements.
SELECT `kid`, `kdata` FROM `keys` WHERE `kuser`='1'
 
If the field name or table name happens to be a keyword, I usually add brackets around the name to make it work.
SELECT kid, kdata FROM [keys] WHERE kuser='1'
Not sure if mysql is any different.
 
Back
Top