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: pgsql-sql@hub.org
Subject: SELECT DISTINCT
Date: Fri, 1 Jan 1999 19:34:00 -0600
Message-ID: <00e801be35ef$f93bbc10$61246ccf@timnt.desm.uswest.net> (raw)

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/





view thread (7+ messages)  latest in thread

Message-ID: <00e801be35ef$f93bbc10$61246ccf@timnt.desm.uswest.net>
Permalink:  ../00e801be35ef$f93bbc10$61246ccf@timnt.desm.uswest.net/
Also on:    postgresql.org/message-id/00e801be35ef$f93bbc10$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, pgsql-sql@hub.org
  Subject: Re: SELECT DISTINCT
  In-Reply-To: <00e801be35ef$f93bbc10$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