Help with rewriting query

Поиск
Список
Период
Сортировка
От Junaili Lie
Тема Help with rewriting query
Дата
Msg-id 8d04ce990506081234121995f9@mail.gmail.com
обсуждение исходный текст
Ответы Re: Help with rewriting query  (Tobias Brox <tobias@nordicbet.com>)
Список pgsql-performance
Hi,
I have the following table:
person - primary key id, and some attributes
food - primary key id, foreign key p_id reference to table person.

table food store all the food that a person is eating. The more recent
food is indicated by the higher food.id.

I need to find what is the most recent food a person ate for every person.
The query:
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)

Thank you in advance.

В списке pgsql-performance по дате отправления:

Предыдущее
От: Matthew Nuzum
Дата:
Сообщение: Re: Help specifying new web server/database machine
Следующее
От: Tobias Brox
Дата:
Сообщение: Re: Help with rewriting query