0% found this document useful (0 votes)
4 views5 pages

HOTS SQL Questions

The document contains a series of SQL questions and corresponding queries related to an EMPLOYEE table, including tasks such as displaying employee names with maximum salary, counting employees by department, and updating salaries. It also highlights common mistakes to avoid when writing SQL queries. Additionally, it provides exam tips for interpreting specific terms in SQL questions.

Uploaded by

achariyacs25
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views5 pages

HOTS SQL Questions

The document contains a series of SQL questions and corresponding queries related to an EMPLOYEE table, including tasks such as displaying employee names with maximum salary, counting employees by department, and updating salaries. It also highlights common mistakes to avoid when writing SQL queries. Additionally, it provides exam tips for interpreting specific terms in SQL questions.

Uploaded by

achariyacs25
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

HOTS SQL Questions

🔹 Case Table: EMPLOYEE


EmpID Name Salary Dept City
101 Ravi 50000 IT Delhi
102 Anu 60000 HR Mumbai
103 John 45000 IT Delhi
104 Meena 70000 Sales Chennai
105 Raj 60000 IT Mumbai

🔥 Questions

1. Display names of employees whose salary is equal to maximum salary.

2. Display second highest salary.

3. Count number of employees in each department.

4. Display departments having more than 1 employee.

5. Display employees whose name starts with 'R'.

6. Display employees whose name ends with 'a'.

7. Display employees who are NOT from Delhi.


8. Display employees with salary between 50000 and 70000.

9. Display unique cities.

10. Display total salary of each department.

11. Display employees sorted by salary (descending).

12. Display highest salary in IT department.

13. Display employees whose salary is greater than average salary.

14. Update salary by 10% for employees in IT department.

15. Delete employees with salary less than 50000.

✅ Answers (Queries)

1.
SELECT Name FROM EMPLOYEE
WHERE Salary = (SELECT MAX(Salary) FROM EMPLOYEE);

2.
SELECT MAX(Salary) FROM EMPLOYEE
WHERE Salary < (SELECT MAX(Salary) FROM EMPLOYEE);
3.
SELECT Dept, COUNT(*)
FROM EMPLOYEE
GROUP BY Dept;

4.
SELECT Dept, COUNT(*)
FROM EMPLOYEE
GROUP BY Dept
HAVING COUNT(*) > 1;

5.
SELECT * FROM EMPLOYEE
WHERE Name LIKE 'R%';

6.
SELECT * FROM EMPLOYEE
WHERE Name LIKE '%a';

7.
SELECT * FROM EMPLOYEE
WHERE City <> 'Delhi';

8.
SELECT * FROM EMPLOYEE
WHERE Salary BETWEEN 50000 AND 70000;

9.
SELECT DISTINCT City FROM EMPLOYEE;

10.
SELECT Dept, SUM(Salary)
FROM EMPLOYEE
GROUP BY Dept;

11.
SELECT * FROM EMPLOYEE
ORDER BY Salary DESC;

12.
SELECT MAX(Salary)
FROM EMPLOYEE
WHERE Dept = 'IT';

13.
SELECT * FROM EMPLOYEE
WHERE Salary > (SELECT AVG(Salary) FROM EMPLOYEE);

14.
UPDATE EMPLOYEE
SET Salary = Salary + Salary*0.10
WHERE Dept = 'IT';

15.
DELETE FROM EMPLOYEE
WHERE Salary < 50000;

🎯 Common Mistakes (VERY


IMPORTANT)
 Forgetting GROUP BY with aggregate functions
 Using WHERE instead of HAVING
 Missing quotes 'Delhi'
 Confusing = and LIKE

⚡ Exam Trick
👉 If question says:

 “group” → GROUP BY
 “condition on group” → HAVING
 “pattern” → LIKE

You might also like