SELECT DISTINCT - Mailing list pgsql-sql

From Tim Perdue, The Des Moines City.net
Subject SELECT DISTINCT
Date
Msg-id 00e801be35ef$f93bbc10$61246ccf@timnt.desm.uswest.net
Whole thread Raw
List 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/



pgsql-sql by date:

Previous
From: Greg Youngblood
Date:
Subject: HELP: Problems with triggers and sql functions
Next
From: Peter Garner
Date:
Subject: Re: [SQL] SELECT DISTINCT