- 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
Is there a way to create a MySQL “alias” while creating a VIEW?
Yes, use the AS keyword to create a MySQL alias. Let us first create a table −
mysql> create table DemoTable ( FirstName varchar(100) ); Query OK, 0 rows affected (0.54 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('Chris'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('Robert'); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable values('Sam'); Query OK, 1 row affected (0.11 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+-----------+ | FirstName | +-----------+ | Chris | | Robert | | Sam | +-----------+ 3 rows in set (0.00 sec)
Following is the query to create a MySQL “alias” −
mysql> create view load_data AS select *from DemoTable; Query OK, 0 rows affected (0.22 sec)
Let us check the records −
mysql> select *from load_data;
This will produce the following output −
+-----------+ | FirstName | +-----------+ | Chris | | Robert | | Sam | +-----------+ 3 rows in set (0.04 sec)
Advertisements