Re: problem with query and group by error - Mailing list pgsql-general

From David Johnston
Subject Re: problem with query and group by error
Date
Msg-id 1393011277471-5793140.post@n5.nabble.com
Whole thread Raw
In response to Re: problem with query and group by error  (Susan Cassidy <susan.cassidy@decisionsciencescorp.com>)
List pgsql-general
Susan Cassidy-3 wrote
> Someone said something about
>  "Yes, except those that are inside the aggregate."
> but I don't have an aggregate specified.

So every column then...

As soon as you add "group by" the rule becomes - every column is either a
group determinate or is aggregated.  If you simply want to remove duplicates
you can write:

Select distinct ... From

No group by clause required and every output column is used to create an
implicit non-duplicated group.

I haven't tried to figure out what you are trying to do with this query so I
don't know which, if either, form is more correct but grouping without
aggregates is unusual and I also find that using distinct is not that common
a need of you have a correctly normalized database.  IOW you should not use
group by or distinct to "make the query work" but only if you
know/understand why doing so is necessary.

David J.




--
View this message in context:
http://postgresql.1045698.n5.nabble.com/problem-with-query-and-group-by-error-tp5793127p5793140.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


pgsql-general by date:

Previous
From: Susan Cassidy
Date:
Subject: Re: problem with query and group by error
Next
From: Brian Crowell
Date:
Subject: Re: GSSAPI server side on Linux, SSPI client side on Windows