MySQL Syntax Error in SELECT Query Using GROUP as Table Name



The group is a reserved keyword, you can’t use it as table name. Therefore, on using it as table name would lead to an error. To avoid such error, you need to use enclosed backticks symbol around the table name ‘group’.

Let us now see an example and create a table −

mysql> create table `group`
   -> (
   -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
   -> Name varchar(20)
   -> );
Query OK, 0 rows affected (1.26 sec)

Insert some records in the table using insert command −

mysql> insert into `group`(Name) values('Chris');
Query OK, 1 row affected (0.47 sec)
mysql> insert into `group`(Name) values('David');
Query OK, 1 row affected (0.36 sec)
mysql> insert into `group`(Name) values('Mike');
Query OK, 1 row affected (0.26 sec)
mysql> insert into `group`(Name) values('Sam');
Query OK, 1 row affected (0.16 sec)

Display all records from the table using select statement −

mysql> select * from `group`;

This will produce the following output −

+----+-------+
| Id | Name  |
+----+-------+
|  1 | Chris |
|  2 | David |
|  3 | Mike  |
|  4 | Sam   |
+----+-------+
4 rows in set (0.00 sec)
Updated on: 2020-02-26T05:39:11+05:30

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements