pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tim Perdue, The Des Moines City.net <tim@dmcity.net>
To: Peter Garner <peter_garner@yahoo.com>
To: pgsql-sql@hub.org
Subject: Re: [SQL] SELECT DISTINCT
Date: Fri, 1 Jan 1999 21:15:23 -0600
Message-ID: <00f301be35fe$23155b00$61246ccf@timnt.desm.uswest.net> (raw)

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@yahoo.com>
To: pgsql-sql@hub.org <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
>




view thread (7+ messages)  latest in thread

Message-ID: <00f301be35fe$23155b00$61246ccf@timnt.desm.uswest.net>
Permalink:  ../00f301be35fe$23155b00$61246ccf@timnt.desm.uswest.net/
Also on:    postgresql.org/message-id/00f301be35fe$23155b00$61246ccf@timnt.desm.uswest.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tim@dmcity.net, peter_garner@yahoo.com, pgsql-sql@hub.org
  Subject: Re: [SQL] SELECT DISTINCT
  In-Reply-To: <00f301be35fe$23155b00$61246ccf@timnt.desm.uswest.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox