0
0
MySQLquery~20 mins

Column aliases in MySQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Column Alias Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2: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;
A[{"first_name": "John", "lname": "Doe"}, {"first_name": "Jane", "lname": "Smith"}]
B[{"first_name": "John", "last_name": "Doe"}, {"first_name": "Jane", "last_name": "Smith"}]
C[{"fname": "John", "last_name": "Doe"}, {"fname": "Jane", "last_name": "Smith"}]
D[{"fname": "John", "lname": "Doe"}, {"fname": "Jane", "lname": "Smith"}]
Attempts:
2 left
💡 Hint
Column aliases rename the output columns in the result set.
📝 Syntax
intermediate
1:30remaining
Which query uses correct syntax for column aliasing?
Choose the query that correctly aliases the column salary as monthly_salary in MySQL.
ASELECT salary AS monthly_salary FROM employees;
BSELECT salary monthly_salary FROM employees;
CSELECT salary : monthly_salary FROM employees;
DSELECT salary -> monthly_salary FROM employees;
Attempts:
2 left
💡 Hint
MySQL uses AS keyword or just a space for aliasing, but some symbols are invalid.
query_result
advanced
2: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;
A[{"total_cost": 200}, {"total_cost": 450}]
B[{"price * quantity": 200}, {"price * quantity": 450}]
C[{"total_cost": "price * quantity"}, {"total_cost": "price * quantity"}]
D[{"price": 200}, {"price": 450}]
Attempts:
2 left
💡 Hint
The alias renames the expression column in the output.
🔧 Debug
advanced
2:00remaining
Why does this query cause an error?
This query tries to alias a column but causes an error:
SELECT first_name AS 'fname' FROM employees;

Why?
AAS keyword cannot be used with column aliases.
BAlias names cannot be shorter than original column names.
CUsing single quotes around alias name causes a syntax error in MySQL.
DColumn names cannot be aliased in SELECT statements.
Attempts:
2 left
💡 Hint
MySQL treats single quotes as string literals, not identifiers.
🧠 Conceptual
expert
2:30remaining
Which statement about column aliases is TRUE?
Choose the correct statement about column aliases in SQL.
AColumn aliases must match the original column names exactly.
BColumn aliases can be used to rename columns only in the output, not in WHERE clause.
CColumn aliases can be used in WHERE clause directly after aliasing.
DColumn aliases permanently rename columns in the database table.
Attempts:
2 left
💡 Hint
Think about when aliases exist during query execution.