Find top SQL resources from global universities, cool projects, and learning materials for data analytics.
Admin: @coderfun
Useful links: heylink.me/DataAnalytics
Promotions: @love_data
Post #2191
4.97K
โ
SQL Practice Questions with Answers ๐ง ๐๏ธ
๐ Q1. How to find the 2nd highest salary from a table?
โ Answer:
๐ Q2. How to find duplicate values in a column?
โ Answer:
๐ Q3. How to select records that exist in one table but not in another?
โ Answer:
๐ Q4. How to get the top 3 highest salaries? (MySQL)
โ Answer:
๐ Q5. How to fetch employees with the same salary?
โ Answer:
๐ Q6. How to get the department-wise highest salary?
โ Answer:
๐ฌ Tap โค๏ธ for more!
๐ Q1. How to find the 2nd highest salary from a table?
โ Answer:
SELECT MAX(salary) FROM employees
WHERE salary < (SELECT MAX(salary) FROM employees);
๐ Q2. How to find duplicate values in a column?
โ Answer:
SELECT name, COUNT(*) FROM employees
GROUP BY name
HAVING COUNT(*) > 1;
๐ Q3. How to select records that exist in one table but not in another?
โ Answer:
SELECT * FROM employees
WHERE id NOT IN (SELECT employee_id FROM payroll);
๐ Q4. How to get the top 3 highest salaries? (MySQL)
โ Answer:
SELECT DISTINCT salary FROM employees
ORDER BY salary DESC
LIMIT 3;
๐ Q5. How to fetch employees with the same salary?
โ Answer:
SELECT * FROM employees e1
WHERE EXISTS (
SELECT 1 FROM employees e2
WHERE e1.salary = e2.salary AND e1.id <> e2.id
);
๐ Q6. How to get the department-wise highest salary?
โ Answer:
SELECT department, MAX(salary) AS max_salary
FROM employees
GROUP BY department;
๐ฌ Tap โค๏ธ for more!
- โค 9
- ๐ 1
- ๐ 1

