简体   繁体   中英

Is there any difference between the different ways of giving an alias name to a table?

I have a table called "Employee" with a column name called "EmployeeName" and I know that all of these different queries will give all the employees in a table:

select EmployeeName from Employee;

select EmployeeName from Employee allEmployees;

select allEmployees.EmployeeName from Employee allEmployees;

select EmployeeName from Employee as allEmployees;

They both bring up all the employees in the table, is the difference between them in terms of query efficiency or running time?

I assume that for simple queries like this, there wouldn't be much difference, but if the above were part of some much longer query, would there be a better one to use? If so, why?

您使用somerandomword作为表别名,这两个查询之间没有区别,它们的输出相同,因为只有一个表 ,但是如果您有两个具有相同列名的不同表,那么这将不起作用,因为存在名称冲突,时间,您必须使用别名或表名。

Aliases are used to give a temporary name to database table OR a column in a table. These are created to make column names more readable.

Wiki

SELECT somerandomword.EmployeeName from Employee somerandomword;
                                                 --------------
                                                   ^This is the alias name for your table

Its safer to get data from columns, especially when we use multiple tables in SELECT query, like below syntax

Syntax :

SELECT t1.col1, t2.col1 from Table_Name1 as t1, Table_Name2 as t2;

Sample Code

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM