
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
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)
- Related Articles
- Return true or false in a MySQL select if another field contains a string?
- Can we compare numbers in a MySQL varchar field?
- Can we implement nested insert with select in MySQL?
- Updating a MySQL column that contains dot (.) in its name?
- How to select objects where an array contains only a specific field in MongoDB?
- Concat a field in MySQL SELECT?
- Can we set a single value in MySQL SELECT IN()?
- Can we use SELECT NULL statement in a MySQL query?
- How can we use MySQL SELECT without FROM clause?
- Can we use a comma between MySQL SELECT statements?
- How can we apply UNIQUE constraint to the field of an existing MySQL table?
- How to generate field in MySQL SELECT?
- Can we give underscore in a MySQL table name?
- Find documents that contains specific field in MongoDB?
- Can we select row by DATEPART() in MySQL? Is it possible?

Advertisements