🔹 Q1. Find nth highest salary?
select salary from employee group by salary desc n-1, 1
select salary from employee where salary = (select distinct(salary) from employee
order by salary desc limit n-1, 1)
select max(salary) from employee where salary < (select max salary from employees);
🔹 2. Write a query to find employees who earn more than their manager.
select e.emp_id, e.salary from employees e JOIN employees m on e.manager_id =
m.emp_id where e.salary > m.salary;
Q3. Find duplicate records in a table.
select name, count(*) from employee group by name having count(*) >1;
🔹 Q4. Delete duplicate rows but keep one.
delete from employee where id not in (select min(id) from employee group by id);
🔹 Q6. Find department with highest average salary.
select department_id from employee group by department_id order by avg(salary) desc
limit 1;
🔹 Q10. Find customers who bought all products.
select customer_id from orders group by customer_id having count(distincy
product_id) = (select count(*) from products);