Don't implement ORDEREDSUBJECT. There aren't any non-broken clients that use it. Implement both threading models the same way- clients that use the THREAD commands don't check the results to see if they used the specific algorithm- and it's a good thing too, because few servers implement this correctly.
I'm not going to test this, but this is very similar to what you need: SELECT a.message_idnr AS qa,b.message_idnr AS qb FROM (SELECT message_idnr,MIN(datefield) FROM dbmail_messages GROUP BY message_idnr,subjectfield) AS a JOIN (SELECT message_idnr message_idnr,subjectfield FROM dbmail_messages GROUP BY subjectfield) AS b USING (subjectfield) this returns two columns, qa is some ancestor of qb. But don't do that! JWZ threading is faster and what people want anyway. On Mon, 2005-08-15 at 17:12 +0200, Paul J Stevens wrote: > Hi all, > > I could use some help here... > > My next target will be server-side threading. All the basics are in > place, but now I need to figure out some smart queries to get this going. > > I'v got this so far: > > get the basic ORDEREDSUBJECT threads for a mailbox: > > select > message_idnr, datefield, subjectfield > from dbmail_messages > join dbmail_subjectfield using (physmessage_id) > join dbmail_datefield using (physmessage_id) > where mailbox_idnr=17 > order by subjectfield, datefield; > > get the start of each thread (the same, but with an added group-by clause): > > select > message_idnr, datefield, subjectfield > from dbmail_messages > join dbmail_subjectfield using (physmessage_id) > join dbmail_datefield using (physmessage_id) > where mailbox_idnr=17 > group by subjectfield > order by subjectfield, datefield; > > Now, the datefield and subjectfield in the select clause are for > debugging purposes only of course. I would like to see if I can combine > these into a single query. > > The basic problem is that using these, the base-subjects are not ordered > by sent-date (datefield). And using a primary sort by datefield won't > let me group by subjectfield like I want to.... > > Any ideas anyone? > > -- Internet Connection High Quality Web Hosting http://www.internetconnection.net/