SQL SELECT AS

w‮‬ww.theitroad.com

In SQL, the SELECT statement is used to retrieve data from one or more tables. The SELECT statement can also be used with the AS keyword to alias column names or to rename a table.

Here are some examples of using SELECT AS:

  1. Alias column name:

Suppose we have a table named "employees" with columns "first_name" and "last_name". We can use AS to create an alias for the column names, like this:

SELECT first_name AS "First Name", last_name AS "Last Name"
FROM employees;

This query will return a result set with two columns named "First Name" and "Last Name", which are aliases for the original column names.

  1. Rename table:

We can also use AS to rename a table in the FROM clause of a SELECT statement, like this:

SELECT *
FROM employees AS emp;

This query will return all columns from the "employees" table, but the table will be referred to as "emp" in the query results.

Note that when using AS to alias column names, the alias is not required to be enclosed in quotation marks, but it is recommended to do so in case the alias contains spaces or special characters.