Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the point using "AS" keyword in SQL when aliasing can be done without it?

  1. Select salary*12 as "Annual Salary" from Employee;
  2. Select salary*12 "Annual Salary" from Employee;

Both queries will give the same result, would "AS" make some difference? if yes, what it is? if no, then what is point using it?

like image 394
M Monis Ahmed Khan Avatar asked Feb 19 '17 11:02

M Monis Ahmed Khan


People also ask

Do you need to use AS in SQL for alias?

SQL aliases are used to give a table, or a column in a table, a temporary name. Aliases are often used to make column names more readable. An alias only exists for the duration of that query. An alias is created with the AS keyword.

What is the use of AS keyword in SQL?

The AS command is used to rename a column or table with an alias. An alias only exists for the duration of the query.

Do you need to use AS for alias?

According to ANSI/ISO SQL the AS keyword is optional. But some dbms products want it, while others don't want it... There's also the alias=columnValue syntax; i.e. select x=1, 2 as y, 3 z used in some DBMS systems.

What is the use of AS keyword with SELECT statement?

The AS keyword in SQL is used to create a temporary alias for a table or column. This alias can be used instead of the name in the SELECT statement.


1 Answers

I think the reason is simple. Consider code such as the following:

select a, b, c, d
. . .

It is very easy to occasionally skip the comma:

select a b, c, d

If you don't use as then this looks like correct code and it can be difficult to figure out. If you always use as for column aliases, then you know it is incorrect.

like image 101
Gordon Linoff Avatar answered Sep 21 '22 21:09

Gordon Linoff