On Friday 16 May 2003 3:46 pm, Sammy wrote:
> Hi,
>
> I have a SQL problem for you all. What SQL qurey would I have to make
> on the following table to extract the chain (thread) of emails in a
> conversation.
>
>
> id|emailid|referenceid
> -----------------------
> 1| e125 | Null (Start of chain)
> 2| r1fe | e125 (2nd letter in chain)
> ...
> ...
> n| e4ju | r1fe (3rd in chain)
Search the archives for "connect by", "hierarchy", "nested" and "celko" - this
is a limitation of SQL. In your particular case, I'd add a SERIAL "thread_id"
column which is autogenerated for the first msg in a thread and set to the
first message for all others.
You might want to check the contrib/ directory, I've got a feeling there's an
example table-function to do something like this.
-- Richard Huxton