
- 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
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)
- Related Articles
- Creating alias in a MongoDB query?
- How to create a MySQL view?
- Is there a way to make a list from a MySQL table in Java?
- Is there a way to know your current username in MySQL?
- Is there a way to select a value which matches partially in MySQL?
- In MySQL, is there a way to turn column records into a list?
- Is there an easy way to rename a table in a MySQL procedure?
- Can we use {} while creating a MySQL table?
- Is there a way in MySQL to reverse a boolean field with a single query?
- Is there a way to subtract number of days from a date in MySQL?
- Is there a way to name columns in an INSERT statement in MySQL?
- Is there a way to retrieve the minimum value of fields in MySQL?
- How to create a table from view in MySQL?
- What is MySQL GENERATED COLUMN and how to use it while creating a table?
- While creating a MySQL table use the reserved keyword ‘Key’

Advertisements