Can we apply DISTINCT to multiple columns in a query?


#1

Question

Can we apply DISTINCT to multiple columns in a query?

Answer

No, the DISTINCT clause can only be used once in the query and will apply only to the column immediately after it.

Any following column names listed after will display their values, but only for the rows with distinct values from the DISTINCT column.

Feel free to test this out in the editor to see what happens!

Example

SELECT DISTINCT year, genre
FROM movies;