pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Peter Garner <peter_garner@yahoo.com>
To: pgsql-sql@hub.org
Subject: Re: [SQL] SELECT DISTINCT
Date: Fri, 1 Jan 1999 18:40:50 -0800 (PST)
Message-ID: <19990102024050.4325.rocketmail@send206.yahoomail.com> (raw)

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: <19990102024050.4325.rocketmail@send206.yahoomail.com>
Permalink:  ../19990102024050.4325.rocketmail@send206.yahoomail.com/
Also on:    postgresql.org/message-id/19990102024050.4325.rocketmail@send206.yahoomail.com

 · 

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: peter_garner@yahoo.com, pgsql-sql@hub.org
  Subject: Re: [SQL] SELECT DISTINCT
  In-Reply-To: <19990102024050.4325.rocketmail@send206.yahoomail.com>

* 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