Because I made a calculation, best practice dictates I give the column a descriptive name using the keyword AS, and then the name surrounded by single quotes, because I have a space in the column name. Using the keyword AS with a name is known as aliasing. Giving an Alias is not required and the database will run the query without the AS ‘Column Name’ syntax; however, the column will have no name and this can get a bit tricky—or even not allowed as you write more sophisticated queries.

We can alias columns, tables, and views; however, don’t make this your best trick. Reading aliases can be tricky, so remember—someone is eventually going to have to review your code. Make good alias names, because that reviewer just might be you.

I also suggest you do not use keywords or reserved words as aliases. Any of the keywords we have mentioned should be avoided. Examples include group, order, count, max, etc.

When there are no spaces in the alias name, you are not required to use single quotes with the alias.

I

Want to follow along on your own database?

Do you want to follow along with the examples?  We have created a sample database you can use to follow along and try in your own database.  Go to the download page and follow the instructions.  Have fun on the SQL trail!