0
0
MySQLquery~10 mins

DISTINCT for unique values in MySQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to select unique city names from the customers table.

MySQL
SELECT [1] city FROM customers;
Drag options to blanks, or click blank then click option'
AONLY
BDISTINCT
CSINGLE
DUNIQUE
Attempts:
3 left
💡 Hint
Common Mistakes
Using UNIQUE instead of DISTINCT, which is not valid in SELECT clause.
Omitting DISTINCT and getting duplicate city names.
2fill in blank
medium

Complete the code to find unique product categories from the products table.

MySQL
SELECT [1] category FROM products;
Drag options to blanks, or click blank then click option'
ADISTINCT
BUNIQUE
CSINGLE
DONLY
Attempts:
3 left
💡 Hint
Common Mistakes
Using UNIQUE which is invalid in SELECT clause.
Forgetting DISTINCT and getting repeated categories.
3fill in blank
hard

Fix the error in the query to select unique customer names.

MySQL
SELECT [1] name FROM customers;
Drag options to blanks, or click blank then click option'
ADISTINCT
BUNIQUE
CSINGLE
DONLY
Attempts:
3 left
💡 Hint
Common Mistakes
Using UNIQUE instead of DISTINCT causes syntax error.
Leaving out DISTINCT and getting duplicates.
4fill in blank
hard

Fill both blanks to select unique countries and order them alphabetically.

MySQL
SELECT [1] country FROM customers ORDER BY country [2];
Drag options to blanks, or click blank then click option'
ADISTINCT
BDESC
CASC
DUNIQUE
Attempts:
3 left
💡 Hint
Common Mistakes
Using UNIQUE instead of DISTINCT.
Using DESC instead of ASC for alphabetical order.
5fill in blank
hard

Fill all three blanks to select unique departments, count employees, and show only those with more than 5 employees.

MySQL
SELECT [1] department, COUNT(*) AS emp_count FROM employees GROUP BY [2] HAVING emp_count [3] 5;
Drag options to blanks, or click blank then click option'
ADISTINCT
Bdepartment
C>
DUNIQUE
Attempts:
3 left
💡 Hint
Common Mistakes
Using UNIQUE instead of DISTINCT.
Grouping by wrong column.
Using wrong comparison operator.