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!