

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 use MySQL keyword as alias name for a column?
Yes, we can use a keyword as alias name for a column. Following is the syntax −
select yourColumnName AS `yourKeywordAsAliasName` from yourTableName;
Above, yourKeywordAsAliasName is the MySQL keyword.
Let us first create a table −
mysql> create table DemoTable (UserId int); Query OK, 0 rows affected (0.74 sec)
Example
Insert some records in the table using insert command −
mysql> insert into DemoTable values(10); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values(11); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values(12); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(13); Query OK, 1 row affected (0.14 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
+--------+ | UserId | +--------+ | 10 | | 11 | | 12 | | 13 | +--------+ 4 rows in set (0.00 sec)
Here is the query to use MySQL keyword as alias name for a column. We have used the keyword ‘PRIMARY KEY’ as the alias name for a column −
mysql> select UserId AS `PRIMARY KEY` from DemoTable;
Output
+-------------+ | PRIMARY KEY | +-------------+ | 10 | | 11 | | 12 | | 13 | +-------------+ 4 rows in set (0.00 sec)
- Related Questions & Answers
- Can we use reserved word ‘index’ as MySQL column name?
- Can we use “rank” as column name with MySQL8?
- Can we use “When” as column name in CREATE TABLE statement?
- Can we use semicolon as a MySQL DEMILITER?
- Can we use “year” as a column came in a MySQL Table?
- Why can't we use column name “desc” in MySQL?
- Can we skip a column name while inserting values in MySQL?
- Can we use current_date() for table with column timestamp default in MySQL?
- Can we use INTERVAL keyword while inserting date records in a MySQL table?
- Can we define a method name same as class name in Java?
- How can we provide an alias name for an action method in Asp .Net MVC C#?
- Can we use backticks with column value in MySQL?
- Can we use the word user for a MySQL table?
- Can we insert values without mentioning the column name in MySQL?
- Wildcards in column name for MySQL?
Advertisements