- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Selecting a column that is also a keyword in 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, consider column name 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)
Following is the query to insert some records in the table using 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)
Following is the query to display records from the table using select command:
mysql> select *from DemoTable;
This will produce the following output:
+-------------+ | select | +-------------+ | Records | | All Data | | Information | +-------------+ 3 rows in set (0.00 sec)
Following 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)
Advertisements