Is there any particular reason (performance or otherwise) to use AS ahead of = when aliasing a column?
My personal preference (for readability) is to use this:
select alias1 = somecolumn alias2 = anothercolumn from tables etc...
instead of this:
select somecolumn as alias1 anothercolumn as alias2 from tables etc...
Am I missing out on any reason why I shouldn't be doing this? What are other people's preferences when it comes to formatting their columns?
Yes, you can alias without AS.
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.
If the alias_name contains spaces, you must enclose the alias_name in quotes. It is acceptable to use spaces when you are aliasing a column name. However, it is not generally good practice to use spaces when you are aliasing a table name.
The basic syntax of a table alias is as follows. SELECT column1, column2.... FROM table_name AS alias_name WHERE [condition];
‘=’ isn't valid ANSI SQL, so you'll have difficulty should you wish to run your application on a different DBMS.
(It's when ANSI form is used but the optional ‘AS’ is omitted I find the results difficult to read, personally.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With