Home  >  Article  >  Database  >  Select a column that is also a MySQL keyword?

Select a column that is also a MySQL keyword?

王林
王林forward
2023-09-05 23:57:021260browse

选择一个同时也是 MySQL 关键字的列?

To select a column that is also a keyword in MySQL, you need to use backticks around the column name. As you know, select is a keyword in MySQL and column names are treated as select when creating a new table.

Let us create a table:

mysql> create table DemoTable (`select` varchar(100));
Query OK, 0 rows affected (0.53 sec)

The following is the query to insert some records in the table using the insert command:

mysql> insert into DemoTable values('Records');
Query OK, 1 row affected (0.18 sec)
mysql> insert into DemoTable values('All Data');
Query OK, 1 row affected (0.15 sec)
mysql> insert into DemoTable values('Information');
Query OK, 1 row affected (0.32 sec)

The following is the query to display the records in the table using the select command Query:

mysql> select *from DemoTable;

This will produce the following output:

+-------------+
| select      |
+-------------+
| Records     |
| All Data    |
| Information |
+-------------+
3 rows in set (0.00 sec)

Below is the query to select a column that is also a keyword in MySQL:

mysql> select `select` from DemoTable;

This will produce the following Output:

+-------------+
| select      |
+-------------+
| Records     |
| All Data    |
| Information |
+-------------+
3 rows in set (0.00 sec)

The above is the detailed content of Select a column that is also a MySQL keyword?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete