Received: from desmpop1.desm.uswest.net (desmpop1.desm.uswest.net [207.108.32.1]) by hub.org (8.9.1/8.9.1) with SMTP id UAA26849 for ; Fri, 1 Jan 1999 20:39:58 -0500 (EST) (envelope-from tim@dmcity.net) Received: (qmail 1502 invoked by alias); 2 Jan 1999 01:39:56 -0000 Delivered-To: fixup-pgsql-sql@hub.org@fixme Received: (qmail 1494 invoked by uid 0); 2 Jan 1999 01:39:56 -0000 Received: from bdsl97.desm.uswest.net (HELO timnt) (207.108.36.97) by desmpop1.desm.uswest.net with SMTP; 2 Jan 1999 01:39:56 -0000 Message-ID: <00e801be35ef$f93bbc10$61246ccf@timnt.desm.uswest.net> Reply-To: "Tim Perdue, The Des Moines City.net" From: "Tim Perdue, The Des Moines City.net" To: Subject: SELECT DISTINCT Date: Fri, 1 Jan 1999 19:34:00 -0600 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 4.72.3110.5 X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 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/