Top 100 SQL Realtime scenarios-based interview questions.
Q1) Write an query to print the salaries of employees above 3000 as high salary or low salary. Ans select ename,sal,case when sal>3000 THEN 'High Salary' ELSE 'Low Salary' END AS salary_category from emp; Q2) Write a query to retreive the last five records from the employee table based on the empno. Ans select * from emp order by empno desc fetch first 5 rows only; select * from ( select * from emp order by empno desc ) where rownum<=5; Note: In oracle, limit clause is not used. You can use FETCH first n rows or ROWNUM to achieve the result. Q3) Write a query to fetch employees who earn more than the average salary. Ans select * from emp where sal>(select avg(sal) from emp); Q4) How do you find the second highest salary from the employee table. Ans select max(sal) from emp where sal<(select max(sal) from emp); Q5) How to find all the duplicate records in the employee table taking all the colum...