Complex SQL Queries Examples
Complex SQL Queries Examples
Answer:
Answer :
Select * from Employee a where rowid <>( select max(rowid) from Employee b where
a.Employee_num=b.Employee_num);
3.How to fetch monthly Salary of Employee if annual salary is given?(click here for
Explaination)
Answer:
4.What is the Query to fetch first record from Employee table? (90% asked Complex SQL
Queries Examples)
Answer:
Answer:
6.What is Query to display first 5 Records from Employee table?(90% asked Complex SQL
Queries Examples)
Answer:
6.What is Query to display last 5 Records from Employee table?(90% asked Complex SQL
Queries Examples)
Answer:
union
select * from (Select * from Employee e order by rowid desc) where rownum <=5;
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
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;
select min(salary)from(select distinct salary from emp order by salary desc)where rownum<=3;
9.How to Display Odd rows in Employee table?(90% asked Complex SQL Queries
Examples)
Answer:
Answer:
Answer:
select * from (Select Dense_Rank() over ( order by salary desc) as Rnk,E.* from Employee E)
where Rnk=3;
12.How Can i create table with same structure of Employee table?(90% asked Complex
SQL Queries Examples)
Answer:
Answer:
select rownum, e.* from emp e where rownum<=(select count(*)/2 from emp);
Answer:
minus
15.How Can i create table with same structure with data of Employee table?
Answer:
Answer:
Intersect
17.Find Query to get information of Employee where Employee is not assigned to the
department
Answer:
Select * from Employee where Dept_no Not in(Select Department_no from Employee);
18.How to get distinct records from the table without using distinct keyword.
Answer:
19.Select all records from Employee table whose name is ‘Amit’ and ‘Pradnya’
Answer:
20.Select all records from Employee table where name not in ‘Amit’ and ‘Pradnya’
Answer:
O/p:
O
R
A
C
L
E
i.e, splitting into multiple columns a string using sql.
Answer:
22.How to fetch all the records from Employee whose joining year is 2017?
Answer:
Oracle:
MS SQL:
24.How Do you find all Employees with its managers?(Consider there is manager id also in
Employee table)
Answer:
25.Display the name of employees who have joined in 2016 and salary is greater than
10000?
Answer:
Select name from Employee where Hire_Date like ‘2016%’ and salary>10000;
**
***
Answer:
We cannot use dual table to display output given above. To display output use any table. I am
using Student table.
Answer :
SELECT
Email
FROM
Employee
where NOT REGEXP_LIKE(Email, ‘[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}’, ‘i’);
Answer:
Tip: User needs to know the concept of Hierarchical queries. Click here to get concept of
hierarchical queries
29.How to remove duplicate rows from table?(100% asked in Complex SQL Queries for
Interviews)
Answer:
Tip: Use concept of max (rowid) of table. Click here to get concept of rowid.
30.How to find count of duplicate rows? (95% asked in SQL queries for Interviews )
Answer:
Group by rollno