Re: [SQL] SELECT DISTINCT

From: "Tim Perdue, The Des Moines City(dot)net" <tim(at)dmcity(dot)net>
To: "Peter Garner" <peter_garner(at)yahoo(dot)com>, <pgsql-sql(at)hub(dot)org>
Subject: Re: [SQL] SELECT DISTINCT
Date: 1999-01-02 03:15:23
Message-ID: 00f301be35fe$23155b00$61246ccf@timnt.desm.uswest.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Thanks - the MIN and GROUP BY did the trick. Here's what I did in the end:

select fld_city, min (fld_zip) from tbl_zip_city where fld_state = 'IA'
group by fld_city;

And now I'm good to go!

Tim
The Des Moines City.net
http://desmoinesnet.com/

-----Original Message-----
From: Peter Garner <peter_garner(at)yahoo(dot)com>
To: pgsql-sql(at)hub(dot)org <pgsql-sql(at)hub(dot)org>
Date: Friday, January 01, 1999 8:46 PM
Subject: Re: [SQL] SELECT DISTINCT

>Hi Tim,
>
>> select distinct fld_city, fld_zip from tbl_zip_city where
>fld_state='IA' and
>> fld_country='us';
>>
>> That query does not return distinct cities any more. It returns all
>cities
>> (because each city can have several zip codes).
>>
>
>Yes, that is what it is supposed to do, heheheh. Try something like :
>
>select city, min (zip_code)
>from tbl_zip_city
>group by city
>having fld_state = 'IA'
>
>Basically since you have multiple zip codes and want only one per city
>you have to tell the sql engine which zip code to pick. It won't just
>select one at random. I hope this helps! :-)
>==
>
>Peace,
>
>Peter
>
>_________________________________________________________
>DO YOU YAHOO!?
>Get your free @yahoo.com address at http://mail.yahoo.com
>

Browse pgsql-sql by date

  From Date Subject
Next Message Engard Ferenc 1999-01-03 00:30:34 c language function
Previous Message Peter Garner 1999-01-02 02:40:50 Re: [SQL] SELECT DISTINCT