sql别名_SQL别名-

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,

表,

IDName
1abhi
2adam
3alex
4anu
5ashish
ID 名称
1个 阿比
2 亚当
3 亚历克斯
4 阿努
5

and the class_info table,

class_info表,

IDAddress
1DELHI
2MUMBAI
3CHENNAI
7NOIDA
8PANIPAT
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,

结果集表将如下所示:

IDNameAddress
1abhiDELHI
2adamMUMBAI
3alexCHENNAI
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时,此别名非常有用。

翻译自: https://www.studytonight.com/dbms/sql-alias.php

sql别名

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值