Choosing SQL with Unique Identifiers

Sorry, my SQL is a little rusty, so it may be trivial, but I can not understand.

I have tabular data like this:

ID LABEL 101 A 102 A 103 A 104 B 105 C 106 C 

I would like to select only different labels, but also have a column with identifiers. Ideally, the result could be:

 ID LABEL 101 A 104 B 105 C 

I don’t care which identifier is selected for the shortcut. Less than ideal id can be any unique integer, for example:

 ID LABEL 1 A 2 B 3 C 

I use SQLite if that matters.

+4
source share
1 answer

This query will do the trick and select the minimum identifier for each label. You just need to specify the name of your table ...

 SELECT MIN(id), LABEL FROM table GROUP BY LABEL ORDER BY MIN(id) 
+12
source

Source: https://habr.com/ru/post/1380729/


All Articles