SQL Aliases

Sometimes you want to change the column names to make them more readable, SQL aliases are used to change the names of tables or columns headings, it is used as follows:


SELECT column_name AS new_name

FROM TableName ;


SELECT column_name

FROM TableName AS new_name ;

Note: The use of the AS keyword is optional but its use is recommended.

Example 1:

     [CardType] AS [Card Type]
    ,[CardNumber] AS [Card Number]
FROM [Sales].[CreditCard];


Example 2:

The columns after a concatenation or computing are not named, it is recommended to rename these columns:

  • Without Alias
     ,[FirstName] +' '+ [LastName] 
FROM [Person].[Person] ;


  • With Alias

Here now with the application of the alias:

SELECT [Title]
      ,[FirstName] +' '+ [LastName] AS [Full Name]
FROM [Person].[Person];


Aliases on a Table

This can help to have shorter names, simpler. This is particularly useful when you use Joins between tables and sometimes it is required in Self-Joins.

You may also like...

Leave a Reply

Your email address will not be published.