you are at Encyclopedia of SQL >> ALIAS
ALLIAS
With ALLIAS we can give table or column another name which will be synonym.
It helps us to shorten long names for tables or columns and it also can make
query more readable for us.
Syntax for creating ALLIAS for column
SELECT `column_name` AS `allias_name`
FROM `table_name`
Syntax for creating ALLIAS for table
SELECT `column_name`
FROM `table_name`
AS `allias_name`
Example
We've two tables `people` and `schools` and we want to display forname, surname and school name
using alliases
query
SELECT o.`forname`,o.`surname`,s.`name`
FROM `people` AS `o`,`schools` AS `s`
WHERE `o`.`surname`='Nowak'
this same query without alliases
SELECT `people`.`forname`,`people`.`surname`,`schools`.`name`
FROM `people`,`schools`
WHERE `people`.`surname`='Nowak'
[ wróć na górę strony ]