pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Martijn van Oosterhout <kleptog@svana.org>
To: FC <lne-1mc8@myamail.com>
Cc: pgsql-general@postgresql.org
Subject: Re: SQL question.
Date: Wed, 1 Jun 2005 17:32:59 +0200
Message-ID: <20050601153255.GB29582@svana.org> (raw)
In-Reply-To: <6EE9301F-4C50-4160-9DC0-667826764A74@myamail.com>
References: <6EE9301F-4C50-4160-9DC0-667826764A74@myamail.com>

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@svana.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.

view thread (71+ messages)  latest in thread

Message-ID: <20050601153255.GB29582@svana.org>
Permalink:  ../20050601153255.GB29582@svana.org/
Also on:    postgresql.org/message-id/20050601153255.GB29582@svana.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: kleptog@svana.org, lne-1mc8@myamail.com
  Subject: Re: SQL question.
  In-Reply-To: <20050601153255.GB29582@svana.org>
  References: <6EE9301F-4C50-4160-9DC0-667826764A74@myamail.com> <20050601153255.GB29582@svana.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox