AS
AS in SQL is used to assign an alias, or temporary name, to a table or a column in a query. This feature enhances readability and allows for more concise code. The assigned alias only exists for the duration of the query.
Example
Output
Name | Age |
---|---|
Peter | 23 |
John | 30 |
Jane | 25 |
Explanation
In the given SQL query, “AS” is used to rename the columns in the output. The column “firstname” is displayed as “Name” and the column “age” as “Age”.
Example
Output
Explanation
In the given SQL code, a table named ‘Employees’ is created with three columns - ‘id’, ‘name’, and ‘salary’. Three rows are inserted into the table with different employee records. The ‘SELECT’ statement is then used with the ‘AS’ keyword to rename ‘name’ column as ‘Employee_Name’ and ‘salary’ column as ‘Employee_Salary’. The ‘AS’ keyword in SQL is used to rename a column or table with an alias. The output section shows the result of the select query.
Example
Output
Explanation
In this SQL statement, it selects a column “first_name” from the table “employee”. The “AS” keyword is used to rename the output header “first_name” to “Name”.
Example
Output
Name | Age |
---|---|
John Doe | 30 |
Jane Doe | 25 |
Amanda Smith | 32 |
David James | 27 |
Explanation
In this example, the AS
keyword is used to rename the columns in the result set. The first_name
column is renamed to Name
and the age
column is renamed to Age
.
Example
Output
Explanation
In SQL, the AS
keyword is primarily used to rename columns or tables with an alias. In the given example, the query renames the columns ‘Name’ and ‘Age’ as ‘User Name’ and ‘User Age’, respectively. The alias name is used to enhance query readability and results interpretation.