Re: select items, and max id

Поиск
Список
Период
Сортировка
От Bruno Wolff III
Тема Re: select items, and max id
Дата
Msg-id 20030829023625.GB4373@wolff.to
обсуждение исходный текст
Ответ на select items, and max id  ("Luis H." <pgsql-novice@geekhouse.no-ip.com>)
Список pgsql-novice
On Thu, Aug 28, 2003 at 22:11:49 -0400,
  "Luis H." <pgsql-novice@geekhouse.no-ip.com> wrote:
> I have a table where each row has an id unique identifier (separate from the one postgreql does automatically). I
wantto be able to do a certain SELECT query returning various rows, and also be able to check what the maximum id was
amongthe rows in the result. Is it possible to do this all in the same query? Right now I do it in a very dumb way -- I
executethe query to get all the data, and then I re-execute it as a subquery and pull out the max(id).  

Yes and no. You won't be able to return rows and the max id of the rows
without effectively doing the query twice. However, you could order the
output rows by the id and check the first (or last depending on sort
direction) row to get the value you want.

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

Предыдущее
От: Bruno Wolff III
Дата:
Сообщение: Re: Force Lock
Следующее
От: "Browne, George (AT-Atlanta)"
Дата:
Сообщение: How does it work