Reputation: 8297
I have city database with country,state,city,postalcode,areacode. The city is not distinct ..for eg one city is repeated for multiple postalcode. I just want the list of distinct city and the first postal code and areacode... if is use distinct it would let me select distinct country state city ...i cannot get other details like areacode...and one of the correct postal code...should i have to write a function to achieve this...
THnks Coool
Upvotes: 2
Views: 215
Reputation: 95203
The following gets you a distinct list of cities and their first postal code (i.e.-the smallest one), which is what the min
does. The group by
clause specifies that you want the min
of postalcode
for each city
.
select
city,
min(postalcode) as zip
from
places
group by
city
Upvotes: 2