Complex SQL Queries Examples
Complex SQL Queries Examples
CLICK HERE TO GET INFORMATION ON NORMALIZATION
6.What is Query to display last 5 Records from Employee table?(90% asked Complex SQL
Queries Examples)
Answer:
Select * from Employee e where rownum <=5
union
select * from (Select * from Employee e order by rowid desc) where rownum <=5;
Click Here to get What is Union?
7.What is Query to display Nth Record from Employee table?
Answer :
select * from ( select a.*, rownum rnum from ( YOUR_QUERY_GOES_HERE — including
the order by ) a where rownum <= N_ROWS ) where rnum >= N_ROWS
8.How to get 3 Highest salaries records from Employee table?
Answer:
select distinct salary from employee a where 3 >= (select count(distinct salary) from
employee b where a.salary <= b.salary) order by a.salary desc;
Alternative Solution: Suggested by Ankit Srivastava
minus
Intersect
22.How to fetch all the records from Employee whose joining year is 2017?
Answer:
Oracle:
Group by rollno