Re: How to do this Query
Posted in 1997
} A slight offshoot of this that does not require a repetitive delete is to } perform the insert into a temp table with a serial column on it. Then } select the Nth row based on the serial value. Something like this: } } create table fred } ( dept_id int, } total int, } serial_id serial) } } insert into fred } select dept_id, count( emp_id ) empcount } from employees } group by 1 } order by 2; } } select dept_id from fred } where serial_id = N; One problem: When using a SELECT as a sub-clause in an INSERT statement, you are limited to a subset of the SELECT syntax. The following SELECT clauses are not supported in this case - INTO TEMP, ORDER BY, and UNION. Additionally, the FROM clause of the SELECT can not reference the same table as referenced by the INSERT (not that that matters here). Mark Collins mcollins@us.dhl.com The problem lies in how easily and dangerously we forget that manipulating things is not the same as understanding them.