[PERFORM] Sort order in sub-select

2006-07-02 Thread Craig A. James
Here is a subtle question about SQL. I have a one-to-many pair of tables (call them "P" and "C" for parent and child). For each row of P, there are many rows in C with data, and I want to sort P on the min(c.data). The basic query is simple: select p_id, min(data) as m from c group by p_id

Re: [PERFORM] Sort order in sub-select

2006-06-29 Thread Tom Lane
"Craig A. James" <[EMAIL PROTECTED]> writes: > insert into hitlist(p_id, sortorder) > (select p_id, nextval('hitlist_seq') from >(select p_id, min(data) as m from c group by p_id order by m); > Apparently, the sort order returned by the innermost select is NOT > maintained as you go

[PERFORM] Sort order in sub-select

2006-06-29 Thread Craig A. James
Here is a question about SQL. I have a one-to-many pair of tables (call them "P" and "C" for parent and child). For each row of P, there are many rows in C with data, and I want to sort P on the min(c.data). The basic query is simple: select p_id, min(data) as m from c group by p_id order b