0

I have a problem with DISTINCT ON. I have five different groups of people which include names and surnames. My goal is to get only one name per group (the first one). When try to use DISTINCT ON, I got an error.

SELECT DISTINCT ON (group_A) surname FROM table

I want my table to look like

group_A...surname_a
broup_B...surname_b
.
.
.

Thank you for your help

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
betd1
  • 81
  • 7

1 Answers1

0

The syntax in Postgres would be:

SELECT DISTINCT ON (group_A) group_A, surname
FROM table
ORDER BY group_A;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786