0
0
SQLquery~20 mins

DISTINCT for unique values in SQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Distinct Mastery
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 DISTINCT query?
Given a table Employees with a column Department containing values: 'Sales', 'HR', 'Sales', 'IT', 'HR', what will this query return?
SELECT DISTINCT Department FROM Employees;
SQL
SELECT DISTINCT Department FROM Employees;
ASales, HR, Sales, IT, HR
BSales, HR, IT
CSales, IT
DHR, IT
Attempts:
2 left
💡 Hint
DISTINCT removes duplicate values and shows only unique ones.
query_result
intermediate
2:00remaining
How many rows does this DISTINCT query return?
Consider a table Orders with a column CustomerID having values: 1, 2, 2, 3, 1, 4.
What is the number of rows returned by this query?
SELECT DISTINCT CustomerID FROM Orders;
SQL
SELECT DISTINCT CustomerID FROM Orders;
A6
B5
C4
D3
Attempts:
2 left
💡 Hint
Count unique CustomerID values only.
📝 Syntax
advanced
2:00remaining
Which query correctly uses DISTINCT to get unique city names?
You want to get unique city names from the Customers table's City column. Which query is correct?
ASELECT DISTINCT City FROM Customers;
BSELECT City DISTINCT FROM Customers;
CSELECT City FROM Customers DISTINCT;
DSELECT City FROM DISTINCT Customers;
Attempts:
2 left
💡 Hint
DISTINCT comes right after SELECT and before column names.
optimization
advanced
2:00remaining
Which query is more efficient to get unique product categories?
You want to list unique product categories from the Products table. Which query is more efficient?
ASELECT Category FROM Products GROUP BY Category;
BSELECT Category FROM Products;
CSELECT Category, COUNT(*) FROM Products;
DSELECT DISTINCT Category FROM Products;
Attempts:
2 left
💡 Hint
DISTINCT is designed to return unique values directly.
🧠 Conceptual
expert
2:00remaining
What error occurs when using DISTINCT with multiple columns incorrectly?
Consider this query:
SELECT DISTINCT Name, Age FROM Employees WHERE Age > 30;

What happens if you try to use DISTINCT on only one column but select multiple columns without specifying DISTINCT properly?
AReturns unique rows based on all selected columns combined
BSyntaxError because DISTINCT must be applied to all selected columns
CReturns unique values only for the first column, ignoring others
DRuntime error due to ambiguous DISTINCT usage
Attempts:
2 left
💡 Hint
DISTINCT applies to the entire row, not just one column.