22

I have a MySQL database with the word "group" in one of the column names. I can't change this database and column's name; it's not mine.

Table users, columns: id, name, password, group, and other. I need to insert a record into this table. I tried INSERT INTO users (name, group) VALUES ('John', '9'), but it's not working because of "group".

Can you help me, how to insert a record into this table, please?

krYsti
  • 221
  • 1
  • 2
  • 4

2 Answers2

32

Try:

INSERT INTO users (`name`, `group`) VALUES ('John', '9')
sikander
  • 2,286
  • 16
  • 23
21

use backticks(`) around column names when you use reserved keywords in query:

INSERT INTO users (`name`,`group`) VALUES ('John', '9')

Read here: Reserved Words

Phil Ross
  • 25,590
  • 9
  • 67
  • 77