Alias columns with meaningful names
To ensure our SQL query results are easily presentable and readable, it almost goes without saying that we should always try our best to name the fields with meaningful content to the business. While figuring out what to name the column can be science plus art, there’s not much to the actual aliasing process itself. Most of the queries in this chapter ended up with the AS
keyword with an alias following. This is all that is needed to ensure the results from a column have a different name.
A simple example is as follows:
Original query:
SELECT TOP (3) [Order Key] ,[Description] FROM [Fact].[Order]
Original results:
Figure 3.21 – Results of the query
Aliased query:
SELECT TOP (3) [Order Key] ,[Description] AS [Product Description] FROM [Fact].[Order]
Aliased results: