Lost your password? Please enter your email address. You will receive a link and will create a new password via email.


You must login to ask a question.

You must login to add post.

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

RTSALL Latest Articles

Most commonly asked SQL Queries | Column Aliases

Most commonly asked SQL Queries | Column Aliases

SQL Queries:- Column Aliases, In the series of most commonly asked questions SQL queries in interviews, are shown below, if you want to learn more or have any topic-related doubts please ask below in the given comment section.

Que. Define SELECT Using Column Aliases in SQL Queries

Column aliases are used mainly to shorten code and make column names more readable. OR
SQL aliases are used to give a table, or a column in a table, a temporary name.

Code becomes shorter as long table names and unnecessary identification of columns can be avoided. Along with table aliases, this allows you to use longer descriptive names in your database structure while keeping queries upon that structure concise.

How we can create column aliases in all versions of Microsoft SQL Server

We can create Aliases in all versions of SQL using double quotes (“).

SELECT
FName AS "First Name",
MName AS "Middle Name",
LName AS "Last Name"
FROM STUDENTS

In the Case of Different Versions:-

We can use single quotes (‘), double quotes (“), and square brackets ([]) to create an alias in Microsoft SQL Server.

SELECT
FName AS "First Name",
MName AS 'Middle Name',
LName AS [Last Name]
FROM STUDENTS

Check Both will result in:

First NameMiddle NameLast Name
JamesJohnSmith
JohnJamesJohnson
MichaelMarcusWilliams
Table:1

The statement will return FName and LName columns with a given name (an alias). This is achieved using the AS operator followed by the alias, or simply writing the alias directly after the column name. This means that the following query has the same outcome as the above.

SELECT
FName "First Name",
MName "Middle Name",
LName "Last Name"
FROM STUDENTS
First NameMiddle NameLast Name
JamesJohnSmith
JohnJamesJohnson
MichaelMarcusWilliams
Table:2

If the alias has a single word that is not a reserved word, we can write it without single quotes, double quotes or brackets:

SELECT
FName AS FirstName,
LName AS LastName
FROM Employees
First NameLast Name
JamesSmith
JohnJohnson
MichaelWilliams
Table:3

Read Also: Most commonly asked SQL Queries Part 2
Most commonly asked SQL Queries Part 1

Related Posts

Leave a comment

You must login to add a new comment.