| From: | Grzegorz Jaśkiewicz <gryzman(at)gmail(dot)com> |
|---|---|
| To: | "Madison Kelly" <linux(at)alteeve(dot)com> |
| Cc: | pgsql-general(at)postgresql(dot)org |
| Subject: | Re: SELECT DISTINCT ... ORDER BY problem |
| Date: | 2008-12-09 09:02:23 |
| Message-ID: | 2f4958ff0812090102r298bffd0w713c3b3fc31400b1@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
On Mon, Dec 8, 2008 at 10:19 PM, Madison Kelly <linux(at)alteeve(dot)com> wrote:
> Hi all,
>
> I've got a table that I am trying to SELECT DISTINCT on one column and
> ORDER BY on a second column, but am getting the error:
>
> SELECT DISTINCT ON expressions must match initial ORDER BY expressions
try
SELECT distinct, array_accum(bar) FROM table WHERE bar < '2008-12-07
16:32:46' AND tbl_id=153 ORDER BY bar LIMIT 1;
or even, when you change bar to proper type - that is, timestamp
SELECT distinct foo, min(bar) as minbar, max(bar) as maxbar FROM
table WHERE bar < '2008-12-07
16:32:46' AND tbl_id=153 ORDER BY bar LIMIT 1;
etc.
Trick, is to use aggregate on other value(s).
HTH
--
GJ
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Grzegorz Jaśkiewicz | 2008-12-09 09:04:32 | Re: SELECT DISTINCT ... ORDER BY problem |
| Previous Message | Liraz Siri | 2008-12-09 08:29:36 | high-availability support for turnkey appliances (for turnkey postgresql and others) |