Using MySQL keywords in a query surrounded with single quotes?


If there are multiple MySQL keywords in a query, use backticks symbol rather than single quotes. Let us first create a table. Here, we have used two reserved keywords i.e. ‘key’ and ‘Limit’ −

mysql> create table DemoTable
(
   `key` int NOT NULL AUTO_INCREMENT PRIMARY KEY ,
   `Limit` int
);
Query OK, 0 rows affected (0.72 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable(`key`,`Limit`) values(null,80);
Query OK, 1 row affected (0.49 sec)
mysql> insert into DemoTable(`key`,`Limit`) values(null,90);
Query OK, 1 row affected (0.10 sec)
mysql> insert into DemoTable(`key`,`Limit`) values(null,100);
Query OK, 1 row affected (0.10 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable;

This will produce the following output &mius;

+-----+-------+
| key | Limit |
+-----+-------+
|   1 |    80 |
|   2 |    90 |
|   3 |   100 |
+-----+-------+
3 rows in set (0.00 sec)

Now, we will select the values of one of the columns, which is declared with the reserved keyword ‘key’. Since, we need to fetch the same records, use the backticks symbol −

mysql> select `key` from DemoTable;

This will produce the following output −

+-----+
| key |
+-----+
|   1 |
|   2 |
|   3 |
+-----+
3 rows in set (0.00 sec)

Updated on: 01-Oct-2019

92 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements