Skip to content
Advertisement

SQL how to select distinct several columns

lets say there are several columns (c1, c2, c3, c4) It’s okay for each column to be appeared several times, but I want to select all the columns with several columns distinct.

I want SELECT c1, DISTINCT(c2, c3), c4 something like this but it doesnt work, and GROUP BY doesnt work as well.

somebody help me please

Advertisement

Answer

You simply can use distrinct on

SELECT DISTINCT ON (c2, c3) *
FROM YOURTABLENAME
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement