Z
Z
Zizibar2020-11-09 14:02:34
PostgreSQL
Zizibar, 2020-11-09 14:02:34

How to display all unique data in a column + to it any random value from another column?

There is a table:
id code key
1 11 111
2 11 222
3 22 333
4 22 444
5 33 555
...
i.e. the key column contains unique values, the code column repeats
You need to make a request so that the response is of the format
code key
11 222
22 333
33 555
i.e. you need to display all unique values ​​from the code column + one first found value from the key column.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2020-11-09
@Zizibar

SELECT DISTINCT ON ("code") "code", "key"
FROM table_name

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question