Re: Sorting by parent/child relationships

Поиск
Список
Период
Сортировка
От Eric Ridge
Тема Re: Sorting by parent/child relationships
Дата
Msg-id D3ADE25911614840BC69C72E3171E4ED0FBD76@tcdiexch.tcdi.com
обсуждение исходный текст
Ответ на Sorting by parent/child relationships  ("Eric Ridge" <ebr@tcdi.com>)
Список pgsql-general
> Some self join would work best I suppose:
>
> select p.*, c.*
> from collection p, collection.c
> where c.parent_id = p.collectionid
> order by p.collectionid ASC, c.collectionid
>
> Depending on your datset you might need to use an outer join instead.
>
> Jochem

Thanks Jochem!  This is almost exactly what I needed, and it's much
cleaner than the ugly monster I started with!  My biggest problem was
that parent rows had a parent_id of -1, when they needed a parent_id of
collection_id to sort correctly.

eric

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Optimizing a complex query (long)
Следующее
От: "mike sears"
Дата:
Сообщение: Broken pipes