pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Haywood J'Bleauxmie <hj1@fc4.outerscape.net>
To: pgsql-sql@postgresql.org
Subject: distinct() vs distinct on ()
Date: Wed, 28 Nov 2001 21:14:43 -0600
Message-ID: <fc.009863ef00009a49009863ef00009a49.9a4a@fc4.outerscape.net> (raw)

Three tables:  LISTING, BROKER, LISTING_BROKER

Each LISTING can have one or more BROKERs so LISTING_BROKER is a link. 
Should not the following be equivalent?


SELECT distinct(l.listing_id)
FROM listing l, broker b, listing_broker lb
WHERE l.listing_id = lb.listing_id
AND b.broker_id = lb.broker_id
AND b.company_id = 1;

SELECT distinct on (l.listing_id) l.listing_id
FROM listing l, broker b, listing_broker lb
WHERE l.listing_id = lb.listing_id
AND b.broker_id = lb.broker_id
AND b.company_id = 1;

The first SELECT does NOT work in that the distinct() is ignored.  The
second SELECT works correctly.  Am I missing something?




view thread (2+ messages)  latest in thread

Message-ID: <fc.009863ef00009a49009863ef00009a49.9a4a@fc4.outerscape.net>
Permalink:  ../fc.009863ef00009a49009863ef00009a49.9a4a@fc4.outerscape.net/
Also on:    postgresql.org/message-id/fc.009863ef00009a49009863ef00009a49.9a4a@fc4.outerscape.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: hj1@fc4.outerscape.net
  Subject: Re: distinct() vs distinct on ()
  In-Reply-To: <fc.009863ef00009a49009863ef00009a49.9a4a@fc4.outerscape.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