distinct / group by assistance.

From: Gavin 'Beau' Baumanis <gavinb(at)eclinic(dot)com(dot)au>
To: pgsql-sql(at)postgresql(dot)org
Subject: distinct / group by assistance.
Date: 2008-06-28 14:32:40
Message-ID: 6A8C2C63-A7E5-410B-B306-28F33D5C1D53@eclinic.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi Everyone,

I am having some issues trying to create the required SQL that will
allow me to return the results I am after.
I have been trying various incarnations, using group by, sub-queries -
albeit to no avail - for the past three hours.

Consider the following simple SQL;

select
a.foo,
b.bar,
c.something
from
table1 a,
inner join
table2 b on b.id =a.id
left outer join
table3 on c.id = a.id

If there a multiple rows of the same id in table1, I get all
(multiple) rows - as you would expect - of course.

What I need however, is only one row returned per instance a.id that
is returned by the above query.

I thought of using group by - but there are no calculated fields...
and the real query contains 32 fields, which according to the errors I
ran into while trying to get this working, would all need to be
included in the group by clause.

So my understanding of group by is obviously a little dodgy - and
obviously not quite what I was expecting.
I tried using a sub query and select distinct a.id..... but that
didn't exactly help either.

I have deliberately included in my example the fact there is an outer
join too - I am not sue if that matters or not... but just in case
thought it prudent to include it here.

Thanks in advance for any help you might have.

Beau.

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2008-06-28 15:43:49 Re: distinct / group by assistance.
Previous Message Tarlika Elisabeth Schmitz 2008-06-27 17:40:21 Re: exclude part of result