AS

SQL AS Keyword

The AS keyword in SQL is used to rename a column or a table with an alias. An alias is a temporary name that only exists during the execution of the query. Aliases are useful for making result sets easier to read or for simplifying complex queries.

Tutorials dojo strip

SQL AS Syntax

For columns:

SQL

For tables:

SQL

SQL AS for Columns

The following SQL statement creates two aliases, one for the first_name column and one for the last_name column from the Patients table:

SQL

The following SQL statement creates two aliases. Notice that it uses double quotes since the alias contains a space:

SQL

The following SQL statement creates an alias named Details that combines three columns (first_name, last_name, and gender):

SQL

Note: In SQLite (used in our playground), || is used to concatenate text values.

SQL AS for Tables

The following SQL statement selects the appointment_date and first_name using aliases for both the Appointments and Patients tables:

SQL

SQL AS Labs

Tutorials dojo strip