| From: | "Andrew J(dot) Kopciuch" <akopciuch(at)bddf(dot)ca> |
|---|---|
| To: | Mike Rylander <mrylander(at)gmail(dot)com> |
| Cc: | pgsql-sql(at)postgresql(dot)org |
| Subject: | Re: sql |
| Date: | 2004-10-25 11:44:06 |
| Message-ID: | 200410250544.06403.akopciuch@bddf.ca |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-sql |
On Monday 25 October 2004 05:20, Mike Rylander wrote:
> SELECT * FROM temp50 GROUP BY gc ORDER BY ora DESC;
You can not have have expressions (columns etc.) in the SELECT list that are
either not in a GROUP BY clause, or used in an aggregate function when you
use GROUP BY in the statement. By saying SELECT *, means you would have to
GROUP BY gc, co, data, ora ...
That isn't going to do what he wants. And the SQL you stated should give you
an error:
ERROR: column "temp50.co" must appear in the GROUP BY clause or be used in an
aggregate function
What he wants to do is use DISTINCT ON:
SELECT DISTINCT ON (gc) gc, co, data, ora FROM temp50 ORDER BY gc, ora DESC;
Andy
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Mike Rylander | 2004-10-25 13:05:39 | Re: sql |
| Previous Message | Mike Rylander | 2004-10-25 11:20:22 | Re: sql |