[Junaili Lie - Wed at 12:34:32PM -0700]
> select f.p_id, max(f.id) from person p, food f where p.id=f.p_id group
> by f.p_id will work.
> But I understand this is not the most efficient way. Is there another
> way to rewrite this query? (maybe one that involves order by desc
> limit 1)
eventually, try something like
select p.id,(select f.id from food f where f.p_id=p.id order by f.id desc limit 1)
from person p
not tested, no warranties.
Since subqueries can be inefficient, use "explain analyze" to see which one
is actually better.
This issue will be solved in future versions of postgresql.
--
Tobias Brox, +47-91700050
Tallinn