Prepare for your Next Interview
This is a discussion on subquery within the SQL forums, part of the Databases category; How to retrive first 5 records, after that update function to be used for those records(first 5 records) using subquery. for 1 record update sal+200 for 2 record ...
|
|||
|
subquery
How to retrive first 5 records, after that update function to be used for those records(first 5 records) using subquery.
for 1 record update sal+200 for 2 record update sal+220 for 3 record update sal+250 for 4th record update sal+300 for 5th record update sal+400 it is possible execute with use of subqueries??? Please help me in this regard. |
| Sponsored Links |
|
|||
|
Re: subquery
Code:
UPDATE tablename
SET sal = sal + 200
WHERE empno = ( SELECT empno
FROM (SELECT rownum rn, num
FROM tablename)
WHERE rn =1);
|
| The Following User Says Thank You to krishnaindia2007 For This Useful Post: | ||
|
|||
|
Re: subquery
below pl/sql block can update sal of first five records.
declare cursor c1 is select rownum,a.* from emp a where rownum<6; c1row c1%rowtype; begin open c1; loop fetch c1 into c1row; exit when c1%notfound; if c1row.rownum=1 then update emp set sal=sal+200 where empno=c1row.empno; elsif c1row.rownum=2 then update emp set sal=sal+220 where empno=c1row.empno; elsif c1row.rownum=3 then update emp set sal=sal+250 where empno=c1row.empno; elsif c1row.rownum=4 then update emp set sal=sal+300 where empno=c1row.empno; elsif c1row.rownum=5 then update emp set sal=sal+400 where empno=c1row.empno; end if; end loop; close c1; end; / |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| SubQuery | chitrab | SQL Server | 3 | 05-24-2007 06:18 AM |
| Join Query without using NOT IN subquery | Geek_Guest | SQL | 1 | 03-07-2007 04:24 PM |