sql别名
Alias is used to give an alias name to a table or a column, which can be a resultset table too. This is quite useful in case of large or complex queries. Alias is mainly used for giving a short alias name for a column or a table with complex names.
别名用于为表或列(也可以是结果集表)命名。 这在大型或复杂查询的情况下非常有用。 别名主要用于为具有复杂名称的列或表提供简短的别名。
Syntax of Alias for table names,
表名称的别名语法,
SELECT column-name FROM table-name AS alias-name
Following is an SQL query using alias,
以下是使用别名SQL查询,
SELECT * FROM Employee_detail AS ed;
Syntax for defining alias for columns will be like,
用于定义列别名的语法类似于:
SELECT column-name AS alias-name FROM table-name;
Example using alias for columns,
对列使用别名的示例,
SELECT customer_id AS cid FROM Emp;
SQL查询中的别名示例 (Example of Alias in SQL Query)
Consider the following two tables,
考虑以下两个表,
The class table,
类表,
ID | Name |
---|---|
1 | abhi |
2 | adam |
3 | alex |
4 | anu |
5 | ashish |
ID | 名称 |
---|---|
1个 | 阿比 |
2 | 亚当 |
3 | 亚历克斯 |
4 | 阿努 |
5 | 灰 |
and the class_info table,
和class_info表,
ID | Address |
---|---|
1 | DELHI |
2 | MUMBAI |
3 | CHENNAI |
7 | NOIDA |
8 | PANIPAT |
ID | 地址 |
---|---|
1个 | 德里 |
2 | 孟买 |
3 | 钦奈 |
7 | 野田 |
8 | 巴拿马型 |
Below is the Query to fetch data from both the tables using SQL Alias,
以下是使用SQL别名从两个表中获取数据的查询,
SELECT C.id, C.Name, Ci.Address from Class AS C, Class_info AS Ci where C.id = Ci.id;
and the resultset table will look like,
结果集表将如下所示:
ID | Name | Address |
---|---|---|
1 | abhi | DELHI |
2 | adam | MUMBAI |
3 | alex | CHENNAI |
ID | 名称 | 地址 |
---|---|---|
1个 | 阿比 | 德里 |
2 | 亚当 | 孟买 |
3 | 亚历克斯 | 钦奈 |
SQL Alias seems to be quite a simple feature of SQL, but it is highly useful when you are working with more than 3 tables and have to use JOIN on them.
SQL别名似乎是SQL的一个非常简单的功能,但是当您使用3个以上的表并且必须在它们上使用JOIN时,此别名非常有用。
sql别名