0
0
MySQLquery~5 mins

DISTINCT for unique values in MySQL - 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.
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.
Click to reveal answer
intermediate
Can DISTINCT be used on multiple columns?
Yes, it returns unique combinations of the specified columns.
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 case sensitive when filtering unique values?
It depends on the database collation settings, but usually it is case insensitive in MySQL by default.
Click to reveal answer
What does SELECT DISTINCT do in SQL?
ACounts the number of rows
BDeletes duplicate rows from the table
CSorts the rows alphabetically
DReturns only unique rows
Which query returns unique combinations of city and state from Customers?
ASELECT DISTINCT city, state FROM Customers;
BSELECT city, state WHERE DISTINCT FROM Customers;
CSELECT UNIQUE city, state FROM Customers;
DSELECT city, state FROM Customers;
If a column has all unique values, what effect does DISTINCT have?
ARemoves all rows
BDuplicates the rows
CReturns the same result as SELECT
DReturns an error
Can DISTINCT be used on multiple columns at once?
AYes, it returns unique combinations of those columns
BNo, only one column at a time
CYes, but only if columns are numeric
DNo, it causes a syntax error
Is DISTINCT case sensitive in MySQL by default?
AYes, always case sensitive
BNo, usually case insensitive depending on collation
CIt depends on the SELECT statement
DIt causes an error if case differs
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 you use DISTINCT on multiple columns in a SELECT statement.
    Consider how two columns together create a unique pair.
    You got /3 concepts.