0
0
MySQLquery~20 mins

DISTINCT for unique values in MySQL - 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?
Consider a table Employees with a column Department containing values: 'Sales', 'HR', 'Sales', 'IT', 'HR'. What will this query return?
SELECT DISTINCT Department FROM Employees;
MySQL
SELECT DISTINCT Department FROM Employees;
ASales, HR, Sales, IT, HR
BSales, HR, IT
CSales, IT
DHR, IT
Attempts:
2 left
💡 Hint
DISTINCT removes repeated values and shows each unique value once.
🧠 Conceptual
intermediate
1:30remaining
Which statement about DISTINCT is true?
Choose the correct statement about the DISTINCT keyword in SQL.
ADISTINCT changes the order of rows returned.
BDISTINCT only works on numeric columns.
CDISTINCT removes duplicate rows based on all selected columns.
DDISTINCT duplicates all rows in the result.
Attempts:
2 left
💡 Hint
Think about what DISTINCT does to repeated data.
📝 Syntax
advanced
1:30remaining
Which query correctly uses DISTINCT to get unique city names?
Given a table Customers with a column City, which query correctly returns unique city names?
ASELECT UNIQUE City FROM Customers;
BSELECT City DISTINCT FROM Customers;
CSELECT City FROM Customers DISTINCT;
DSELECT DISTINCT City FROM Customers;
Attempts:
2 left
💡 Hint
DISTINCT comes right after SELECT.
optimization
advanced
2:00remaining
Which query is more efficient to get unique product categories?
You want to list unique product categories from a large Products table. Which query is more efficient?
ASELECT DISTINCT Category FROM Products;
BSELECT Category FROM Products GROUP BY Category;
CSELECT Category FROM Products;
DSELECT ALL Category FROM Products;
Attempts:
2 left
💡 Hint
DISTINCT and GROUP BY can both get unique values, but one is simpler and often faster.
🔧 Debug
expert
2:30remaining
Why does this query return duplicates despite DISTINCT?
Given a table Orders with columns OrderID, CustomerID, and OrderDate, why does this query return duplicate CustomerIDs?
SELECT DISTINCT CustomerID, OrderDate FROM Orders;
ADISTINCT applies to all selected columns, so different OrderDates cause duplicates.
BDISTINCT only works on the first column listed.
CDISTINCT is ignored when multiple columns are selected.
DDISTINCT removes duplicates only if OrderID is included.
Attempts:
2 left
💡 Hint
DISTINCT looks at the whole row, not just one column.