Hi there

How are you?
Would you please explain how the following queries work

//alternate rows
select * from emp where rowid in (select decode(mod(rownum,2),0,rowid, null) from emp); 

//3rd max salary
select distinct sal from emp e1 where 3 = (select count(distinct sal) from emp e2 where e1.sal <= e2.sal); 

//top n
select * from emp where rownum <= &n; 

//bottom n
select * from emp minus select * from emp where rownum <= (select count(*) - &n from emp); 

Thank you

What database are you using? Can you show the table structure for emp?

EMP table has two attributes viz. empno(varchar2(10)) and empname(varchar2(10)).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.