Challenge - 5 Problems
Column Alias Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
What is the output of this query with column aliases?
Consider a table employees with columns
id, first_name, and last_name. What will be the output column names of this query?SELECT first_name AS fname, last_name AS lname FROM employees;
MySQL
SELECT first_name AS fname, last_name AS lname FROM employees;
Attempts:
2 left
💡 Hint
Column aliases rename the output columns in the result set.
✗ Incorrect
Using AS keyword renames the output columns to the alias names specified. So first_name becomes fname and last_name becomes lname in the output.
📝 Syntax
intermediate1:30remaining
Which query uses correct syntax for column aliasing?
Choose the query that correctly aliases the column
salary as monthly_salary in MySQL.Attempts:
2 left
💡 Hint
MySQL uses AS keyword or just a space for aliasing, but some symbols are invalid.
✗ Incorrect
The correct syntax uses AS keyword or a space. Option A is valid in MySQL but less clear. Option A is the standard and recommended syntax. Options C and D use invalid symbols.
❓ query_result
advanced2:00remaining
What is the output of this query with expression alias?
Given a table
orders with columns price and quantity, what is the output of this query?SELECT price * quantity AS total_cost FROM orders;
MySQL
SELECT price * quantity AS total_cost FROM orders;
Attempts:
2 left
💡 Hint
The alias renames the expression column in the output.
✗ Incorrect
The expression price * quantity is calculated for each row and the result is shown under the column named total_cost.
🔧 Debug
advanced2:00remaining
Why does this query cause an error?
This query tries to alias a column but causes an error:
Why?
SELECT first_name AS 'fname' FROM employees;
Why?
Attempts:
2 left
💡 Hint
MySQL treats single quotes as string literals, not identifiers.
✗ Incorrect
In MySQL, alias names should not be enclosed in single quotes because single quotes denote strings. Use backticks or no quotes for aliases.
🧠 Conceptual
expert2:30remaining
Which statement about column aliases is TRUE?
Choose the correct statement about column aliases in SQL.
Attempts:
2 left
💡 Hint
Think about when aliases exist during query execution.
✗ Incorrect
Column aliases exist only in the output of the SELECT statement and cannot be used in WHERE clause because WHERE is evaluated before SELECT.