I am unclear on exactly on,
SELECT DISTINCT col1, col2, ...
FROM table_name
When called on one column it gives back only distinct values of that column. What happens when we use it with multiple columns and should we ever do this?
distinctpostgresql
I am unclear on exactly on,
SELECT DISTINCT col1, col2, ...
FROM table_name
When called on one column it gives back only distinct values of that column. What happens when we use it with multiple columns and should we ever do this?
Best Answer
It gives you distinct combinations of all the expression in the
SELECT
list.is also equivalent to:
Another way to look at how it works - probably more accurate - is that it acts as the common bare
SELECT
(ALL
) and then removes any duplicate rows. See Postgres documentation aboutSELECT
:DISTINCT
clause.Of course. If you need it, you can use it.