Home > Database > Mysql Tutorial > body text

Select a column that is also a MySQL keyword?

王林
Release: 2023-09-05 23:57:02
forward
1283 people have browsed it

选择一个同时也是 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)
Copy after login

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)
Copy after login

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

mysql> select *from DemoTable;
Copy after login

This will produce the following output:

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

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

mysql> select `select` from DemoTable;
Copy after login

This will produce the following Output:

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

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!