Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Basic MySQL problem

Tags:

sql

mysql

Why doesn't SELECT * FROM users_meta where user = 1 and key = tagline work?

It works without the key = tagline. But I need that!

users_meta is a table with these fields:
id, key, value, user.

I'm trying get the value from a row with key = tagline and user = 1.

Thanks!

like image 768
dot Avatar asked Jul 01 '26 19:07

dot


2 Answers

It is because key is a MySQL keyword. If it is also a column name in your table, then you need to surround it in backticks. Like:

`key` = 'tagline'
like image 70
Paul Avatar answered Jul 03 '26 12:07

Paul


Syntax. Backticks around reserved words used as identifiers, single quotes around string literals.

SELECT * FROM users_meta WHERE user = 1 AND `key` = 'tagline'
like image 35
Dan Grossman Avatar answered Jul 03 '26 12:07

Dan Grossman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!