Re: SELECT DISTINCT ... ORDER BY problem

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:04:32
Message-ID: 2f4958ff0812090104t29e6e35br8b69d5c3aa1c3da7@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Dec 9, 2008 at 9:02 AM, Grzegorz Jaśkiewicz <gryzman(at)gmail(dot)com> wrote:
> 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;

but than (after sec of thinking), you could just do

SELECT foo, min(bar) AS minbar, max(bar) AS maxbar FROM table
WHERE ..blabla.. GROUP BY foo ORDER BY maxbar LIMIT 1;

--
GJ

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Grzegorz Jaśkiewicz 2008-12-09 09:06:20 Re: Problem Related to storing the field value in a String
Previous Message Grzegorz Jaśkiewicz 2008-12-09 09:02:23 Re: SELECT DISTINCT ... ORDER BY problem