SQL AS

SQL AS  can be used to give alias name to a table or a column .

Syntax

For table

SELECT * FROM table_name AS alias_name

For column

SELECT column_name AS alias_name FROM table_name

MySQL Table – users

+—-+——+
| id | name |
+—-+——+
|  1 | PHP  |
|  2 | JS   |
|  3 | HTML |
|  5 | ASP  |
+—-+——+

Example

mysql> SELECT * FROM users as lan;
+—-+——+
| id | name |
+—-+——+
|  1 | PHP  |
|  2 | JS   |
|  3 | HTML |
|  5 | ASP  |
+—-+——+
4 rows in set (0.00 sec)

mysql> SELECT name as lan FROM users;
+——+
| lan  |
+——+
| PHP  |
| JS   |
| HTML |
| ASP  |
+——+
4 rows in set (0.00 sec)

Share