SELECT DISTINCT

From: "Tim Perdue, The Des Moines City(dot)net" <tim(at)dmcity(dot)net>
To: <pgsql-sql(at)hub(dot)org>
Subject: SELECT DISTINCT
Date: 1999-01-02 01:34:00
Message-ID: 00e801be35ef$f93bbc10$61246ccf@timnt.desm.uswest.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

I have been trying to do a SELECT DISTINCT from a pgsql table and am having
trouble. I've tried subselects, EXISTS, IN, etc, and have had no luck.

I want the query to select all the cities in a state, eliminating
duplicates. I also want the ZIP code (any one of that city's zip codes)
returned in the result set.

select distinct fld_city from tbl_zip_city where fld_state='IA' and
fld_country='us';

That query returns half of what I want (distinct city), but does not return
the associated zip code.

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).

Any suggestions?

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

Browse pgsql-sql by date

  From Date Subject
Next Message Peter Garner 1999-01-02 02:40:50 Re: [SQL] SELECT DISTINCT
Previous Message Greg Youngblood 1998-12-31 19:33:54 HELP: Problems with triggers and sql functions