Re: Getting row with id=max(id) - Mailing list pgsql-sql

From Tom Lane
Subject Re: Getting row with id=max(id)
Date
Msg-id 10021.992018040@sss.pgh.pa.us
Whole thread Raw
In response to Getting row with id=max(id)  (Gerald Gutierrez <gml1@coldresist.com>)
List pgsql-sql
Gerald Gutierrez <gml1@coldresist.com> writes:
> I'd like to get the row with ID=4. I've tried:
> SELECT * FROM mytable WHERE id=(SELECT MAX(id) FROM mytable);
> The subquery can take a /really/ long time on a table that is large. The query:
> SELECT * FROM mytable ORDER BY id DESC LIMIT 1;
> doesn't seem to help very much.

It should help a lot, if you have an index on id.  Have you vacuum
analyzed the table recently?
        regards, tom lane


pgsql-sql by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: Re: About i8n
Next
From: "Josh Berkus"
Date:
Subject: Re: [HACKERS] Re: behavior of ' = NULL' vs. MySQL vs. Standards