Re: Sorting by parent/child relationships - Mailing list pgsql-general

From Eric Ridge
Subject Re: Sorting by parent/child relationships
Date
Msg-id D3ADE25911614840BC69C72E3171E4ED0FBD76@tcdiexch.tcdi.com
Whole thread Raw
In response to Sorting by parent/child relationships  ("Eric Ridge" <ebr@tcdi.com>)
List 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 by date:

Previous
From: Tom Lane
Date:
Subject: Re: Optimizing a complex query (long)
Next
From: "mike sears"
Date:
Subject: Broken pipes