A column alias is a temporary name given to a column in the result set of a query to make the output easier to read or understand.
Click to reveal answer
beginner
How do you use the AS keyword in SQL?
You use AS to assign a new name (alias) to a column or expression in the SELECT statement, like: SELECT column_name AS alias_name FROM table_name;
Click to reveal answer
beginner
Why would you use a column alias in a query?
To make column names more readable, to rename complex expressions, or to prepare output for reports or user interfaces.
Click to reveal answer
intermediate
Can you use column aliases without the AS keyword?
Yes, in many SQL dialects you can write SELECT column_name alias_name FROM table_name; but using AS improves clarity.
Click to reveal answer
beginner
Example: Write a query to select the column 'price' from 'products' table and rename it to 'Cost'.
SELECT price AS Cost FROM products;
Click to reveal answer
What does the AS keyword do in SQL?
ADeletes a column from a table
BCreates a new table
CAssigns a temporary name to a column or expression
DFilters rows in a query
✗ Incorrect
AS is used to give a temporary name (alias) to a column or expression in the query result.
Which of the following is a correct way to alias a column named 'salary' as 'Income'?
ASELECT salary AS Income FROM employees;
BSELECT salary Income FROM employees;
CSELECT salary = Income FROM employees;
DSELECT salary INTO Income FROM employees;
✗ Incorrect
The correct syntax uses AS to assign the alias: SELECT salary AS Income FROM employees;
Is the AS keyword mandatory when creating a column alias?
AOnly mandatory in SELECT * queries
BYes, always mandatory
COnly mandatory for table aliases
DNo, it is optional in many SQL dialects
✗ Incorrect
AS is optional in many SQL dialects but recommended for clarity.
What will this query return? SELECT price AS Cost FROM products;
AA column named 'Cost' with data from 'price'
BAll columns from products table
CAn error because AS is not allowed
DA column named 'price' with original data
✗ Incorrect
The query returns the 'price' column data but names the column 'Cost' in the output.
Why might you want to use a column alias?
ATo change the data type of a column
BTo make output easier to read or understand
CTo permanently rename a column in the table
DTo delete a column from the table
✗ Incorrect
Column aliases help make query results clearer without changing the actual table.
Explain what a column alias is and how to use the AS keyword in SQL.
Think about how you rename columns temporarily in query results.
You got /3 concepts.
Describe why column aliases are useful when writing SQL queries.
Consider how output looks to users or reports.
You got /3 concepts.
Practice
(1/5)
1. What is the purpose of using AS in an SQL query when selecting columns?
easy
A. To filter rows based on a condition
B. To rename the column in the output result
C. To join two tables together
D. To delete a column from the table
Solution
Step 1: Understand the role of AS in SQL SELECT
The AS keyword is used to give a temporary name (alias) to a column or expression in the output.
Step 2: Identify what AS does in the query result
It changes how the column header appears, making the output easier to read or understand.
Final Answer:
To rename the column in the output result -> Option B
Quick Check:
Column alias = rename column [OK]
Hint: AS renames columns in output, not data itself [OK]
Common Mistakes:
Thinking AS filters rows
Confusing AS with JOIN
Believing AS deletes columns
2. Which of the following SQL queries correctly uses AS to alias the column price as cost?
easy
A. SELECT price IS cost FROM products;
B. SELECT price TO cost FROM products;
C. SELECT price AS cost FROM products;
D. SELECT price = cost FROM products;
Solution
Step 1: Review correct syntax for column aliasing
The correct syntax uses AS between the original column name and the alias.
Step 2: Check each option for correct usage
Only SELECT price AS cost FROM products; uses AS properly: price AS cost. Others use invalid keywords or operators.
Final Answer:
SELECT price AS cost FROM products; -> Option C
Quick Check:
Correct alias syntax uses AS [OK]
Hint: Use AS between column and alias name [OK]
Common Mistakes:
Using TO instead of AS
Using IS or = instead of AS
Omitting AS but using invalid syntax
3. Given the table 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;
medium
A. fname, lname
B. first_name, last_name
C. first_name AS fname, last_name AS lname
D. fname AS first_name, lname AS last_name
Solution
Step 1: Understand alias effect on output column names
The AS keyword renames the output columns to the alias names given.
Step 2: Identify the aliases used in the query
The columns first_name and last_name are aliased as fname and lname respectively.
Final Answer:
fname, lname -> Option A
Quick Check:
Aliases become output column names [OK]
Hint: Output columns show alias names, not original names [OK]
Common Mistakes:
Expecting original column names in output
Confusing alias syntax with output format
Thinking AS changes table column names
4. Identify the error in this SQL query:
SELECT product_name AS, price FROM products;
medium
A. No error, query is correct
B. AS keyword should be lowercase
C. Comma should be after AS
D. Missing alias name after AS
Solution
Step 1: Check the syntax of the alias usage
The AS keyword must be followed by the alias name immediately.
Step 2: Identify the missing alias name
In the query, product_name AS is incomplete because no alias name is given after AS.
Final Answer:
Missing alias name after AS -> Option D
Quick Check:
AS must be followed by alias name [OK]
Hint: AS must always have a name after it [OK]
Common Mistakes:
Leaving AS without alias name
Thinking AS case matters
Misplacing commas around AS
5. You want to display the total sales amount from a sales table with column amount. Which query correctly sums the amounts and shows the result with the column name Total_Sales?
hard
A. All of the above
B. SELECT SUM(amount) Total_Sales FROM sales;
C. SELECT SUM(amount) AS 'Total_Sales' FROM sales;
D. SELECT SUM(amount) AS Total_Sales FROM sales;
Solution
Step 1: Understand aliasing with aggregate functions
You can alias the result of SUM(amount) using AS or by just placing the alias after the expression.
Step 2: Check each option for correctness
SELECT SUM(amount) AS Total_Sales FROM sales; uses AS with underscore alias, valid. SELECT SUM(amount) Total_Sales FROM sales; omits AS but alias after expression is valid. SELECT SUM(amount) AS 'Total_Sales' FROM sales; uses AS with quoted alias, also valid in many SQL dialects.
Step 3: Confirm all options produce correct output
All options correctly rename the output column to the desired alias.
Final Answer:
All of the above -> Option A
Quick Check:
Aliases can use AS, omit AS, or use quotes [OK]
Hint: Aliases can be with AS, without AS, or quoted [OK]
Common Mistakes:
Thinking AS is always required
Not quoting aliases with spaces
Confusing alias with column name
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.