Re: Help with simple query - Mailing list pgsql-sql

From PFC
Subject Re: Help with simple query
Date
Msg-id op.s2iujcjfcigqcu@apollo13
Whole thread Raw
In response to Help with simple query  (Collin Peters <cadiolis@gmail.com>)
List pgsql-sql
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 ?


pgsql-sql by date:

Previous
From: Frank Bax
Date:
Subject: Re: Help with simple query
Next
From: "George Pavlov"
Date:
Subject: Re: Help with simple query