Bug #645 'AS' not mandatory in column aliases
Submitted: 12 Jun 2003 16:48 Modified: 1 Jul 2003 14:01
Reporter: Gianluca Gillini Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Documentation Severity:S3 (Non-critical)
Version: OS:
Assigned to: Paul DuBois CPU Architecture:Any

[12 Jun 2003 16:48] Gianluca Gillini
Description:
This seems to be a bug in documentation, but it could look like a bug in MySql.
Documentations states clearly you can omit AS when defining a table alias, but it doesn't say the same about column aliases. It's not much clear, because there isn't a syntax definition of "select_expression" (6.4.1 "SELECT" syntax), but it tells "A SELECT expression may be given an alias using AS. The alias is used as the expression's column name and can be used with ORDER BY or HAVING clauses." This is followed by an example using 'AS'.

In reality, MySql allows you to define a column alias without AS. You can write "SELECT column alias FROM..." and it works (tested in 4.0.12, 4.0.1, 3.23.56)

So, if you forget a comma between two column names in SELECT clause, you'll get the contents of the first column under the name of the second one, 'cause MySql reads it like an alias, while someone could expect to get an error.

How to repeat:
Imagine to have tableA which columns are col1 and col2: if you write
SELECT col1 col2 FROM tableA
you'll get

col2
col1's content
col1's content
col1's content

Suggested fix:
Upgrade documentation
[1 Jul 2003 14:01] Indrek Siitan
Thanks for the bug report. This has now been clarified at:
http://www.mysql.com/doc/en/SELECT.html