0
0
SQLquery~5 mins

DISTINCT for unique values in SQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the SQL keyword DISTINCT do?
It removes duplicate rows from the result set, showing only unique values for the selected columns.
Click to reveal answer
beginner
How would you select unique city names from a table called Customers?
Use SELECT DISTINCT city FROM Customers; to get only unique city names without duplicates.
Click to reveal answer
intermediate
Can DISTINCT be used with multiple columns?
Yes, it returns unique combinations of the specified columns. For example, SELECT DISTINCT city, country FROM Customers; shows unique city-country pairs.
Click to reveal answer
beginner
What happens if you use DISTINCT on a column with all unique values?
The result will be the same as a normal SELECT because all values are already unique.
Click to reveal answer
intermediate
Is DISTINCT applied before or after sorting in a query?
DISTINCT is applied before sorting. The database first removes duplicates, then sorts the results if ORDER BY is used.
Click to reveal answer
What does the SQL keyword DISTINCT do?
ASorts the result in ascending order
BRemoves duplicate rows from the result
CLimits the number of rows returned
DJoins two tables together
Which query returns unique countries from the table Customers?
ASELECT DISTINCT country FROM Customers;
BSELECT UNIQUE country FROM Customers;
CSELECT country FROM Customers;
DSELECT country WHERE DISTINCT FROM Customers;
If you use DISTINCT on two columns, what do you get?
AAll rows without filtering
BUnique values from the second column only
CUnique values from the first column only
DUnique combinations of both columns
What will happen if all values in a column are already unique and you use DISTINCT?
AAn error will occur
BDuplicates will be removed
CThe result will be the same as a normal SELECT
DThe query will run slower but results change
When is DISTINCT applied in the order of query operations?
ABefore ORDER BY
BBefore WHERE
CAfter GROUP BY
DAfter ORDER BY
Explain how the DISTINCT keyword works in SQL and give an example query.
Think about how you would find unique items in a list.
You got /3 concepts.
    Describe what happens when DISTINCT is used with multiple columns in a SELECT statement.
    Imagine filtering unique pairs instead of single values.
    You got /3 concepts.