sql别名无效

Sql Alias

SQL别名

There are cases when the column name or the table name that is existing in the database is not so human readable. We can use SQL ALIAS feature to assign a new name to the table or columns in our query.
在某些情况下,数据库中存在的列名或表名不是很容易理解。 我们可以使用SQL ALIAS功能为查询中的表或列分配新名称。

SQL ALIAS is used for temporary naming of table or column of a table for making it more readable. The renaming is temporary in nature and does not affect the real name of the table or the column of the table.

SQL ALIAS用于​​临时命名表或表的列,以使其更具可读性。 重命名本质上是临时的,不会影响表或表的列的真实名称。

The lifetime of the SQL ALIAS is till the duration of the query where SQL ALIAS is defined.

SQL ALIAS的生存期一直到定义SQL ALIAS的查询持续时间为止。

SQL ALIAS is more useful where multiple tables are involved like in case of JOINS.

SQL ALIAS在涉及多个表(如JOINS的情况)时更有用。

We will discuss the usage of SQL ALIAS for table and column name of the table in detail in the below-mentioned sections.

我们将在以下各节中详细讨论表的表名和列名SQL ALIAS用法。

表名称SQL别名 (SQL Alias For Table Name)

Syntax:

语法

SELECT column_name(s) FROM table_name AS alias_name;

In the syntax above the alias_name is the name that will be temporarily assigned for the table_name.

在上面的语法中,alias_name是将临时分配给table_name的名称。

Let’s try an understand in detail about aliasing a table name using the below-mentioned example.

让我们尝试使用下面提到的示例来详细了解有关别名表名称的信息。

We will consider the below mentioned Product and Supplier table for example purpose.

我们将以下面提到的“产品和供应商”表为例。

Product Table:

产品表:

ProductID ProductName SupplierID
1 Cookies 2
2 Jam 2
3 Butter 1
4 Bread 3
5 Cake 1
产品编号 产品名称 供应商编号
1个 饼干 2
2 果酱 2
3 牛油 1个
4 面包 3
5 蛋糕 1个

Supplier Table:

供应商表:

SupplierID SupplierName
1 ABC
Company
2 ACD Industries
3 XYZ Pvt
Ltd
供应商编号 供应商名称
1个 美国广播公司
公司
2 ACD产业
3 XYZ列印
有限公司

Scenario: Get the name of all the products and their supplier name along with the productid.

场景 :获取所有产品的名称及其供应商名称以及productid。

SQL Select Query:

SQL选择查询:

SELECT p.ProductID, p.ProductName, s.SupplierName FROM Product AS p, Supplier AS s WHERE p.SupplierID = s.SupplierID;
ProductID ProductName SupplierName
1 Cookies ACD
Industries
2 Jam ACD Industries
3 Butter ABC Company
4 Bread XYZ Pvt Ltd
5 Cake ABC Company
产品编号 产品名称 供应商名称
1个 饼干 ACD
产业领域
2 果酱 ACD产业
3 牛油 ABC公司
4 面包 XYZ Pvt Ltd
5 蛋糕 ABC公司

In the output above SQL ALIAS, is used for aliasing the table name, making it easy to differentiate the two SupplierID columns of Product and Supplier table.

在SQL ALIAS上方的输出中,使用别名表名称,可以轻松区分Product和Supplier表的两个SupplierID列。

列名称SQL别名 (SQL Alias For Column Name)

Syntax:

句法:

SELECT column_name AS alias_name FROM table_name;

In the syntax above the alias_name is the name that will be temporarily assigned for the column_name.

在上面的语法中,alias_name是将为column_name临时分配的名称。

Let’s try an understand in detail about aliasing a column name using the below-mentioned example.

让我们尝试使用下面提到的示例来详细了解有关别名别名的信息。

Scenario: Get the name of all the products and their supplier name along with the productid. The ProductName column should be displayed as Product and SupplierName column should be displayed as Supplier.

场景 :获取所有产品的名称及其供应商名称以及productid。 ProductName列应显示为Product,而SupplierName列应显示为Supplier。

Query:

查询:

SELECT p.ProductID, p.ProductName AS Product, s.SupplierName AS Supplier FROM Product AS p, Supplier AS s WHERE p.SupplierID = s.SupplierID;
ProductID Product Supplier
1 Cookies ACD Industries
2 Jam ACD Industries
3 Butter ABC Company
4 Bread XYZ Pvt Ltd
5 Cake ABC Company
产品编号 产品 供应商
1个 饼干 ACD产业
2 果酱 ACD产业
3 牛油 ABC公司
4 面包 XYZ Pvt Ltd
5 蛋糕 ABC公司

In the example above we have seen the usage of alias for table and column both in a single query.

在上面的示例中,我们已经在单个查询中看到了表和列别名的用法。

翻译自: https://www.journaldev.com/24784/sql-alias

sql别名无效

sql别名无效_SQL别名相关推荐

  1. sql多层嵌套别名无效_SQL之复杂查询

    前文学了汇总分析,学了常见的汇总函数,会分组并且掌握了对分组结果指定条件.今天开始学习SQL的视图和子查询,还有数据库关联与嵌套查询内容的学习. 一.视图 1.1视图是有单固定存储可反复读取使用的子查 ...

  2. java执行sql列名无效_Sql异常:列名无效

    Quote: System.Data.SqlClient.SqlException:'无效的列名'Mugs'.' 我不确定错误,因为我从一段代码中复制了另一个完美无缺的表格. 我使用按钮上的文本从数据 ...

  3. SQL查询语句起别名

    SQL查询语句起别名 --直接写后面 select dept_id deptID from dept; --加AS再写后面 select dept_id as deptID from dept; -- ...

  4. SQL SERVER设置服务器别名

    今天遇到一个问题,看书上说可以设置SQL SERVER服务器的别名,就可以通过别名来访问服务器,不需要使用计算机名或者IP地址了.这样做有一个好处,假如数据库服务器名或者IP地址发生变化,只需要修改别 ...

  5. mysql union all 别名_MySQL Union合并查询数据及表别名、字段别名用法分析

    本文实例讲述了MySQL Union合并查询数据及表别名.字段别名用法.分享给大家供大家参考,具体如下: union关键字 SELECT s_id, f_name, f_price FROM frui ...

  6. oracle 动态sql列转行_SQL优化笔记分享:34条实用经验可别错过!

    SQL 优化经验 1. 选择最有效率的表名顺序(只在基于规则的优化器中有效)ORACLE 的解析器按照从右到左的顺序处理FROM子句中的表名,FROM子句中写在最后的表(基础表 driving tab ...

  7. mysql 别名_MySQL 字段别名(列别名)

    SQL 字段别名 同本文前文讲述的表别名一样,SQL(MySQL) 也支持对表的字段(列)设置别名. 字段别名语法: SELECT column AS column_alias FROM table ...

  8. mysql 表别名_MySQL 表别名(Alias)

    SQL 表别名 在 SQL 语句中,可以为表名称及字段(列)名称指定别名(Alias),别名是 SQL 标准语法,几乎所有的数据库系统都支持.通过关键字 AS 来指定. 表别名语法: SELECT c ...

  9. oracle账户别名,Oracle的别名

    在SQL语句中,可以给表和列起别名,这是临时的别名,与同义词不一样,同义词是永久的别名. 别名是多表查询和嵌套查询语句的基础知识,本文只介绍别名的语法,不涉及别名的应用技巧,大家在学习的时候可能觉得别 ...

最新文章

  1. 4行代码,让app自动化框架支持 webview 混合应用操作
  2. RequestParam注解在required设置为true时失效
  3. BZOJ2986 Non-Squarefree Numbers
  4. 46 关于Linux的I/O重定向
  5. 慕课网高并发实战(一)-并发与高并发基本概念
  6. 【前端模板之路】二、人肉非智举,让代码帮我们写代码才是王道
  7. ubuntu下安装绿联的AC650网卡驱动
  8. ESD试验与设备介绍
  9. 软件测试面包屑什么意思,面包屑的用法面包屑有什么作用
  10. Millet谷仓对电商的三大革命
  11. UOJ#454. 【UER #8】打雪仗
  12. 【解决方案】windows系统部分软件变日文
  13. 静态方法能被重写么?
  14. SQL SERVER2008局域网内连不上问题
  15. 在ACM的巨坑里挣扎的弱鸡整理的模板
  16. opencv在linux系统下利用从cv2进行摄像头读取操作
  17. 开源自主导航小车MickX4(二)ROS底盘运动控制
  18. 开源应用程序打包工具
  19. IE和FireFox的Javascript的事件和事件处理总结
  20. 亚马逊AI被曝性别歧视?人事部门却在悄悄给女性“开绿灯”

热门文章

  1. bzoj4546-codechef XRQRS(可持久化Trie)
  2. PHP正则表达式详解(三)
  3. 排序算法(二)Sort with Swap(0,*)
  4. 创建数据库、表以及索引
  5. [转载] python staticmethod有什么意义_Python 中的 classmethod 和 staticmethod 有什么具体用途
  6. [转载] Python日历模块| 使用示例的weekday()方法
  7. 欧拉线性筛 与 欧拉函数 + 几道例题
  8. .NET日志工具介绍
  9. BSD Socket~TCP~Example Code
  10. 再谈System.arraycopy和Arrays.copyOf