- 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
Can we select field name in MySQL that contains an asterisk?
No, we cannot. To still work it out, use backticks around the field name. Let us first create a table with column name with asterisk, `Name*` −
mysql> create table DemoTable -> ( -> `Name*` varchar(20) -> ); Query OK, 0 rows affected (2.03 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable(`Name*`) values('Chris Brown'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(`Name*`) values('David Miller'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable(`Name*`) values('John Doe'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable(`Name*`) values('John Smith'); Query OK, 1 row affected (0.23 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+--------------+ | Name* | +--------------+ | Chris Brown | | David Miller | | John Doe | | John Smith | +--------------+ 4 rows in set (0.00 sec)
Following is the query to select field name which contains an asterisk −
mysql> select `Name*` from DemoTable;
This will produce the following output −
+--------------+ | Name* | +--------------+ | Chris Brown | | David Miller | | John Doe | | John Smith | +--------------+ 4 rows in set (0.00 sec)
Advertisements