PDQ.com mobilePDQ.com desktop
SQL clauses and order of operation

Episode 2 – Renaming a Column with an Alias

Stephanie WarnerStephanie Warner

Episode 1 left off using a simple SQL query SELECTing four columns FROM the Computers table in PDQ Inventory:

SELECT ComputerId,
FROM Computers

When writing SQL queries there will be times, for any reason, you’d rather call a column by a different name. You can easily rename a column (or table, introduced in a future video and blog post) using an alias. An alias is a temporary name and is only active during the span of the query.

An alias is not a permanent name change

The alias is always written directly after the column name using the AS command. Include the alias in single quotes:

Query 1 Alias
SELECT ComputerId,       
Name AS ‘Computer Name’,
FROM Computers

TIP: The last column in a SELECT statement never has any punctuation after it. Notice how all other columns are separated by commas. If you accidentally leave a comma after the last column of your SELECT statement, you will receive a syntax error. In PDQ Inventory, the syntax error looks something like: 

SQL syntax error

Expanding the error description by clicking the blue question mark symbol will show you a more detailed visual:

more info window

The description states the error is ‘near "FROM". This is because the FROM statement is directly after the syntax error.

Check out a live video here.

Don't miss the next post!

How PowerShell can calculate your retirement

How PowerShell can track 401K growth

In this blog, I use PowerShell to focus and build a 401k calculator because its tax advantages make it ideal to build your retirement nest egg.