Re: SQL question.

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: FC <lne-1mc8(at)myamail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: SQL question.
Date: 2005-06-01 15:32:59
Message-ID: 20050601153255.GB29582@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Jun 01, 2005 at 04:40:48PM +0200, FC wrote:
>
> Hello SQL Aces !
>
> I want to do a select on a table distinct on linkid and sorted by
> date. I have try this

How about a subquery?:

SELECT * FROM
( SELECT DISTINCT ON (linkid) * FROM all_links
WHERE uid='2' AND DATE_TRUNC('day',read_date) = DATE_TRUNC('day',
TIMESTAMP '2005-06-01') ORDER BY linkid, read_date) AS sub
ORDER BY read_date DESC limit 100;

Hope this helps,

> My question is... How can I do the same thing in the more efficient
> way and without using a temporary table. Since I am using PHP and the
> table is not deleted at the end of the program because PHP keeps the
> connection to the database open.
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Richard Huxton 2005-06-01 15:37:01 Re: Old problem needs solution
Previous Message Gerald D. Anderson 2005-06-01 15:24:25 Old problem needs solution