aph
07-24-2002, 02:36 PM
Hi,
Please consider the following example:
Let's say we have table emp with the following values:
SQL> select deptno, ename, job, sal from emp;
DEPTNO ENAME JOB SAL
--------- ---------- --------- ---------
20 SMITH CLERK 800
30 ALLEN SALESMAN 1600
30 WARD SALESMAN 1250
20 JONES MANAGER 2975
30 MARTIN SALESMAN 1250
30 BLAKE MANAGER 2850
10 CLARK MANAGER 2450
20 SCOTT ANALYST 3000
10 KING PRESIDENT 5000
30 TURNER SALESMAN 1500
20 ADAMS CLERK 1100
30 JAMES CLERK 950
20 FORD ANALYST 3000
10 MILLER CLERK 1300
14 rows selected.
Requirement:
We need to pick 1st row of each deptno from emp and insert into emp1 table. 1st mean actual 1st row of emp table.
E.g.:
20 SMITH CLERK 800
30 ALLEN SALESMAN 1600
10 CLARK MANAGER 2450
Now the above three rows should be insert in emp1 table, means emp1 containing 3 rows.
I have tried too many ways to get this done, but fail to achieve the query. It would be nice if you could provide some solution.
Thanks.
Please consider the following example:
Let's say we have table emp with the following values:
SQL> select deptno, ename, job, sal from emp;
DEPTNO ENAME JOB SAL
--------- ---------- --------- ---------
20 SMITH CLERK 800
30 ALLEN SALESMAN 1600
30 WARD SALESMAN 1250
20 JONES MANAGER 2975
30 MARTIN SALESMAN 1250
30 BLAKE MANAGER 2850
10 CLARK MANAGER 2450
20 SCOTT ANALYST 3000
10 KING PRESIDENT 5000
30 TURNER SALESMAN 1500
20 ADAMS CLERK 1100
30 JAMES CLERK 950
20 FORD ANALYST 3000
10 MILLER CLERK 1300
14 rows selected.
Requirement:
We need to pick 1st row of each deptno from emp and insert into emp1 table. 1st mean actual 1st row of emp table.
E.g.:
20 SMITH CLERK 800
30 ALLEN SALESMAN 1600
10 CLARK MANAGER 2450
Now the above three rows should be insert in emp1 table, means emp1 containing 3 rows.
I have tried too many ways to get this done, but fail to achieve the query. It would be nice if you could provide some solution.
Thanks.