1

I would like to select some parameters in a column of my database. The issue that I have is that the column where I want to select the data is named "set".

SELECT * FROM database.table where set=5130;

"Set" is also a keyword in MySQL which leads to an error :

Error Code: 1064. 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 'set=5130' at line 1

How should I bypass this issue ?

FraJarJar
  • 13
  • 5
  • 2
    Maybe this question about quoting helps https://stackoverflow.com/q/11321491/1741542. Basically use backticks around `set`. – Olaf Dietsche Apr 21 '21 at 10:06
  • Bypass it by not using any keywords as column names. It's just a pain. – maio290 Apr 21 '21 at 10:07
  • Thank you for your reply ! Sadly I can't change the column name, I didn't create the database, I'm working on it. I'll use backsticks. – FraJarJar Apr 21 '21 at 10:38

2 Answers2

0

I guess changing the column name is not an option for you. Then you need to use backticks (`).

SELECT * FROM database.table where `set`=5130;
aatwork
  • 2,130
  • 4
  • 17
0

The best approach would probably be to rename the column. If this is not an option, you can escape it by surrounding it with backticks:

SELECT * FROM database.table WHERE `set` = 5130;
-- Here ---------------------------^---^
Mureinik
  • 297,002
  • 52
  • 306
  • 350