0
0
SQLquery~10 mins

DISTINCT for unique values in SQL - 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.

SQL
SELECT [1] city FROM customers;
Drag options to blanks, or click blank then click option'
ADISTINCT
BUNIQUE
CALL
DSINGLE
Attempts:
3 left
💡 Hint
Common Mistakes
Using UNIQUE instead of DISTINCT, which is not standard SQL.
Omitting DISTINCT and getting duplicate city names.
2fill in blank
medium

Complete the code to count how many unique product names are in the products table.

SQL
SELECT COUNT([1]) FROM products;
Drag options to blanks, or click blank then click option'
AALL product_name
BDISTINCT product_name
Cproduct_name
DUNIQUE product_name
Attempts:
3 left
💡 Hint
Common Mistakes
Using COUNT(product_name) which counts all rows, not unique ones.
Using UNIQUE inside COUNT, which is not valid SQL.
3fill in blank
hard

Fix the error in the query to select unique customer IDs from orders.

SQL
SELECT [1] customer_id FROM orders;
Drag options to blanks, or click blank then click option'
AUNIQUE
BSINGLE
CONLY
DDISTINCT
Attempts:
3 left
💡 Hint
Common Mistakes
Using UNIQUE which causes syntax error.
Using ONLY or SINGLE which are not valid SQL keywords here.
4fill in blank
hard

Complete the code to select unique combinations of first and last names from employees.

SQL
SELECT [1] first_name, last_name FROM employees;
Drag options to blanks, or click blank then click option'
AUNIQUE
BALL
CDISTINCT
DSINGLE
Attempts:
3 left
💡 Hint
Common Mistakes
Putting DISTINCT before both columns, which causes syntax error.
Using UNIQUE instead of DISTINCT.
5fill in blank
hard

Fill all three blanks to select unique department names and count employees in each department.

SQL
SELECT [1] department_name, COUNT([2]) FROM employees GROUP BY [3];
Drag options to blanks, or click blank then click option'
ADISTINCT
B*
Cdepartment_name
DALL
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting DISTINCT and getting duplicate department names.
Using COUNT(department_name) instead of COUNT(*).
Not grouping by department_name.