A table can be temporarily renamed to another name dynamically using ALIAS command
Syntax:
SELECT column1, column2..
FROM table_name AS alias_name
WHERE [condition];
Example:
Suppose we have this customers table
cust_id | cust_name | address | city | postal_code | country |
---|---|---|---|---|---|
1 | Maria Anders | Obere Str. 57 | Berlin | 12209 | Germany |
2 | Fran Wilson | C/ Araquil, 67 | Madrid | 28023 | Spain |
3 | Dominique Perrier | 25, rue Lauriston | Paris | 75016 | France |
4 | Martin Blank | Via Monte Bianco 34 | Turin | 10100 | Italy |
5 | Thomas Hardy | 89 Chiaroscuro Rd. | Portland | 97219 | USA |
6 | Christina Aguilera | Gran Va, 1 | Madrid | 28001 | Spain |
7 | Hanna Moos | Forsterstr. 57 | Mannheim | 68306 | Germany |
SELECT cust_name, city, country FROM customers AS people where cust_id <6
it will create an alias table name people with those columns.
cust_name | city | country |
---|---|---|
Maria Anders | Berlin | Germany |
Fran Wilson | Madrid | Spain |
Dominique Perrier | Paris | France |
Martin Blank | Turin | Italy |
Thomas Hardy | Portland | USA |
Learn more : SQL Tutorial , SQL Interview Questions