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 WAA04443 for ; Fri, 1 Jan 1999 22:21:33 -0500 (EST) (envelope-from tim@dmcity.net) Received: (qmail 21474 invoked by alias); 2 Jan 1999 03:21:30 -0000 Delivered-To: fixup-pgsql-sql@hub.org@fixme Received: (qmail 21458 invoked by uid 0); 2 Jan 1999 03:21:29 -0000 Received: from bdsl97.desm.uswest.net (HELO timnt) (207.108.36.97) by desmpop1.desm.uswest.net with SMTP; 2 Jan 1999 03:21:29 -0000 Message-ID: <00f301be35fe$23155b00$61246ccf@timnt.desm.uswest.net> Reply-To: "Tim Perdue, The Des Moines City.net" From: "Tim Perdue, The Des Moines City.net" To: "Peter Garner" , Subject: Re: [SQL] SELECT DISTINCT Date: Fri, 1 Jan 1999 21:15:23 -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 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 To: pgsql-sql@hub.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 >