From: PFC <lists@peufeu.com>
To: Collin Peters <cadiolis@gmail.com>
To: pgsql-sql@postgresql.org
Subject: Re: Help with simple query
Date: Thu, 29 Dec 2005 02:31:50 +0100
Message-ID: <op.s2iujcjfcigqcu@apollo13> (raw)
In-Reply-To: <df01c91b0512281558h3b760e89v80b4354e99183e99@mail.gmail.com>
References: <df01c91b0512281558h3b760e89v80b4354e99183e99@mail.gmail.com>
If you want the latest by user, you can cheat a bit and use the fact that
the id's are incrementing, thus ordering by the id
is about the same as ordering by the date field. I know it can be inexact
in some corner cases, but it's a good approximation, and
very useful in practice :
SELECT user_id, max(note_id) FROM notes GROUP by user_id;
So :
SELECT * FROM notes WHERE id IN (SELECT max(note_id) FROM notes GROUP by
user_id) ;
Can postgres use the index on these max() clauses now ?
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 using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: lists@peufeu.com, cadiolis@gmail.com
Subject: Re: Help with simple query
In-Reply-To: <op.s2iujcjfcigqcu@apollo13>
* 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