Concept Flow - Column aliases with AS
Write SELECT statement
Specify column names
Use AS to rename columns
Execute query
Result shows new column names
This flow shows how to rename columns in a query result using AS, making output easier to read.
SELECT first_name AS Name, age AS AgeYears FROM users;
| Step | Action | Input | Output |
|---|---|---|---|
| 1 | Start query execution | SELECT first_name AS Name, age AS AgeYears FROM users; | Prepare to read users table |
| 2 | Read first row from users | Row: {first_name: 'Alice', age: 30} | Apply aliases: Name='Alice', AgeYears=30 |
| 3 | Read second row from users | Row: {first_name: 'Bob', age: 25} | Apply aliases: Name='Bob', AgeYears=25 |
| 4 | Read third row from users | Row: {first_name: 'Carol', age: 27} | Apply aliases: Name='Carol', AgeYears=27 |
| 5 | No more rows | End of table | Return result set with aliased columns |
| Variable | Start | After 1 | After 2 | After 3 | Final |
|---|---|---|---|---|---|
| Name | N/A | Alice | Bob | Carol | Carol |
| AgeYears | N/A | 30 | 25 | 27 | 27 |
SELECT column_name AS alias_name Use AS to rename columns in query output. Aliases improve readability without changing table. Alias names appear in result headers. AS keyword is optional but recommended for clarity.
AS in an SQL query when selecting columns?AS in SQL SELECTAS keyword is used to give a temporary name (alias) to a column or expression in the output.AS does in the query resultAS to alias the column price as cost?AS between the original column name and the alias.AS properly: price AS cost. Others use invalid keywords or operators.employees with columns first_name and last_name, what will be the output column name of this query?SELECT first_name AS fname, last_name AS lname FROM employees;
AS keyword renames the output columns to the alias names given.first_name and last_name are aliased as fname and lname respectively.SELECT product_name AS, price FROM products;
AS keyword must be followed by the alias name immediately.product_name AS is incomplete because no alias name is given after AS.sales table with column amount. Which query correctly sums the amounts and shows the result with the column name Total_Sales?SUM(amount) using AS or by just placing the alias after the expression.AS with underscore alias, valid.AS but alias after expression is valid.AS with quoted alias, also valid in many SQL dialects.Pass the test and this pattern moves unknown