Write query for the following questions1. sql query for selecting alternate rows in a table2. sql query for deleting alternate rows in a table

Showing Answers 1 - 16 of 16 Answers

Sanjay Mungekar

  • Aug 21st, 2006
 

select * from emp where (rowid,0) in (select rowid,mod(rownum,2) from emp)

 

select * from emp where (rowid,0) not in (select rowid,mod(rownum,2) from emp)

  Was this answer useful?  Yes

krsihna

  • Aug 30th, 2006
 

the answer is at first i was inserted the data into the table with the use of this query we can get the even positions of records from that particular table

  Was this answer useful?  Yes

Arumugaraj

  • Sep 21st, 2006
 

When i run this query it shows error such as

'mod' is not a recognized function name'

why?

  Was this answer useful?  Yes

1)select empno from (select empno,rownum rn from emp order by empno desc) it where mod(it.rn,2)=02)delete from emp where rowid in (select rd from (select empno,rowid rd,rownum rn from emp rder by empno desc) it where mod(it.rn,2)=0http://360.yahoo.com/suresh.kandukuru

  Was this answer useful?  Yes

bhumip

  • Jan 1st, 2007
 

For Alternating row (MS SQL)select id from stud a where (select count(*) from stud where a.id>id)%2=0

  Was this answer useful?  Yes

bku

  • Jan 13th, 2007
 

The query works fine, but cant find the logic behind it...

  Was this answer useful?  Yes

SQL> select last_name,salary,rn from (select b.*,rownum rn from (select last_name,salary   from employees)b) where mod(rn,2) = 0;

LAST_NAME                     SALARY         RN
------------------------- ---------- ----------
Kochhar                        17000          2
Hunold                          9000          4
Lorentz                         4200          6
Rajs                            3500          8
Matos                           2600         10
Zlotkey                        10500         12
Taylor                          8600         14
Whalen                          4400         16
Fay                             6000         18
Gietz                           8300         20

10 rows selected.

For deleting them This is the query.


  1* delete from emp_bkup where rowid in (select rd from (select employee_id,rowid rd,rownum rn from emp_bkup)b where mod(b.rn,2)=0)
SQL> /

10 rows deleted.

SQL> select count(1) from emp_bkup;

  COUNT(1)
----------
        10

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions