Philippe
Philippe

Reputation: 93

SQL Select one column only with distinct on another column

From this list:

Id  Material
5   100% Alpaca
8   100% Alpaca
32  100% Alpaca
113 100% Alpaca
271 100% Alpaca
437 100% Alpaca
114 100% Alpaca (Baby Royal)
115 100% Alpaca (Baby Royal)
116 100% Alpaca (Baby Royal)
250 100% Alpaca (Baby)
395 100% Alpaca (Royal)
176 100% Alpaca (Super Fine)
231 100% Alpine Stone Sheep
329 100% Alpine Stone Sheep
330 100% Alpine Stone Sheep
380 100% Aluminum
192 100% Angora
193 100% Angora
194 100% Angora

I would like only the 1st Id (to use for a cursor) on a distinct Material Result expected:

Id
5   
114 
250 
395 
176 
231 
380 
192 

Any suggestion ?

Upvotes: 0

Views: 47

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269463

Use min()?

select min(id)
from t
group by material;

Upvotes: 1

Related Questions