In SQL not using AS is a bad practice? Why? Is it documented somewhere?

Question:

I read (if I remember correctly in a post or a comment to a question on Stackoverflow in English) that not using AS for aliases in SQL was a bad practice.

I usually use my queries without AS when they are aliases, because it seems more elegant to me, for example:

SELECT COUNT(*) total FROM tabla t1 INNER JOIN tabla2 t2 ON t1.id=t2.id;
SELECT MAX(id)  mayor FROM tabla ... 

Instead of:

SELECT COUNT(*) AS total FROM tabla AS t1 INNER JOIN tabla2 AS t2 ON t1.id=t2.id;
SELECT MAX(id)  AS mayor FROM tabla ... 

I was looking for example in the MySQL Reference Manual and I didn't find anything that explicitly says that not using AS is a bad practice.

In short, I want to know if not using AS is a bad practice. If it is, why is it and where is it documented?

The question asks about SQL in general, not specific handlers.

Answer:

The ISO/IEC 9075 standard in the query specification indicates that:


7.12 < query specification >

This Subclause is modified by Subclause 7.1,“”,
in ISO/IEC 9075-4.

Function

Specify a table derived from the result of a .

Format

< query specification > ::=
  SELECT [ < set quantifier > ] < select list >< table expression >

< select list > ::= < asterisk > | < select sublist > [ { < comma >< select sublist > }... ]

< select sublist > ::=< derived column > | < qualified asterisk >

< qualified asterisk > ::= < asterisked identifier chain >< period >< asterisk > | < all fields reference >

< asterisked identifier chain > ::= < asterisked identifier> [ { < period >< asterisked identifier > }... ]

< asterisked identifier > ::=< identifier >

< derived column > ::= < value expression > [ < as clause > ] 

< as clause > ::= [ AS ] < column name >

< all fields reference > ::= < value expression primary >< period >< asterisk > [ AS < left paren >< all fields column name list >< right paren > ]

< all fields column name list > ::= < column name list >

We are interested:

 < as clause > ::= [ AS ] < column name >

If the documentation is interpreted as usual, the square brackets indicate that what they highlight is optional, which is why the word AS to indicate the alias of the column is optional under the specification.

I know that in the question we talked about tables but I don't think they differ in this concept.

I don't think it's bad practice to leave it without the AS , I'd bet that it's left that way for compatibility issues.

I leave the link to the draft of the standard that I found on the web (Page 377): http://jtc1sc32.org/doc/N1801-1850/32N1822T-text_for_ballot-CD_9075-2.pdf

Scroll to Top