0% found this document useful (0 votes)
8 views

SQL Question Bank

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

SQL Question Bank

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

FIRST_NAM LAST_NAM

WORKER_ID E E SALARY JOINING_DATE DEPARTMENT

001 Monika Arora 100000 2021-02-20 09:00:00 HR

002 Niharika Verma 80000 2021-06-11 09:00:00 Admin

003 Vishal Singhal 300000 2021-02-20 09:00:00 HR

004 Amitabh Singh 500000 2021-02-20 09:00:00 Admin

005 Vivek Bhati 500000 2021-06-11 09:00:00 Admin

006 Vipul Diwan 200000 2021-06-11 09:00:00 Account

007 Satish Kumar 75000 2021-01-20 09:00:00 Account

008 Geetika Chauhan 90000 2021-04-11 09:00:00 Admin


Sample Table – Worker
Worker Table
Sample Table – Bonus
WORKER_REF_ID BONUS_DATE BONUS_AMOUNT

1 2023-02-20 00:00:00 5000

2 2023-06-11 00:00:00 3000

3 2023-02-20 00:00:00 4000

1 2023-02-20 00:00:00 4500

2 2023-06-11 00:00:00 3500


Bonus Table
WORKER_REF_ID WORKER_TITLE AFFECTED_FROM

1 Manager 2023-02-20 00:00:00

2 Executive 2023-06-11 00:00:00

8 Executive 2023-06-11 00:00:00

5 Manager 2023-06-11 00:00:00

4 Asst. Manager 2023-06-11 00:00:00

7 Executive 2023-06-11 00:00:00

6 Lead 2023-06-11 00:00:00

3 Lead 2023-06-11 00:00:00

Sample Table – Title


Title Table

QUESTIONS:
1. Write an SQL query to fetch “FIRST_NAME” from the Worker table using the alias name
<WORKER_NAME>
2. Write an SQL query to fetch “FIRST_NAME” from the worker table in upper case.
3. Write an SQL query to etch unique values of DEPARTMENT from the worker table.
4. Write an SQL query to print the first three characters of First_name from the worker table.
5. Write an SQL query to find the position of the alphabet (‘a’) in the first name column
‘Amithab’ from the worker table.
6. Write an SQL query to print the FIRST_NAME from the worker table after removing white
spaces from the right side.
7. Write an SQL query to print the DEPARTMENT from the Worker table after removing white
spaces from the left side.
8. Write an SQL query that fetches the unique values of DEPARTMENT from the Worker table
and prints its length.
9. Write an SQL query to print the FIRST_NAME from the Worker table after replacing ‘a’ with
‘A’.
10. Write an SQL query to print the FIRST_NAME and LAST_NAME from the Worker table into a
single column COMPLETE_NAME. A space character should separate them.
11. Write an SQL query to print all Worker details from the Worker table ordered by
FIRST_NAME in ascending order.
12. Write an SQL query to print all Worker details from the Worker table ordered by
FIRST_NAME in ascending order and DEPARTMENT in descending order.
13. Write an SQL query to print details for Workers with the first names “Vipul” and “Satish”
from the Worker table.
14. Write an SQL query to print details of Workers excluding first names, “Vipul” and “Satish”
from the Worker table.
15. Write an SQL query to print details of Workers with DEPARTMENT name as “Admin”.
16. Write an SQL query to print details of the Workers whose FIRST_NAME contains ‘a’.
17. Write an SQL query to print details of the Workers whose FIRST_NAME ends with ‘a’.
18. Write an SQL query to print details of the Workers whose FIRST_NAME ends with ‘h’ and
contains six alphabets.
19. Write an SQL query to print details of the Workers whose SALARY lies between 100000 and
500000.
20. Write an SQL query to print details of the Workers who joined in Feb 2021.

Intermediate SQL Queries


15. Write an SQL query to fetch the count of employees working in the department ‘Admin’.
16. Write an SQL query to fetch worker names with salaries >= 50000 and <= 100000.
17. Write an SQL query to fetch the number of workers for each department in descending
order.
18. Write an SQL query to print details of the Workers who are also Managers.
19. Write an SQL query to fetch duplicate records having matching data in some fields of a table.
20. Write an SQL query to show only odd rows from a table.
21. Write an SQL query to show only even rows from a table.
22. Write an SQL query to clone a new table from another table.
23. Write an SQL query to fetch intersecting records of two tables.
24. Write an SQL query to show records from one table that another table foes not have.
25. Write an SQL query to find the employees who have the same salary and department as
their manager.
26. Write an SQL query to retrieve the cumulative salary for each employee considering the
running total within their department.

Advanced SQL Queries


25. Write an SQL query to determine the nth (say n = 5) highest salary from a table.
26. Write an SQL query to determine the 5th highest salary without using the TOP or limit
method.
27. Write an SQL query to fetch the list of employees with the same salary.
28. Write an SQL query to show the second highest salary from a table.
29. Write an SQL query to show one row twice in the results from a table.
30. Write an SQL query to fetch intersecting records of two tables.
31. Write an SQL query to fetch the first 50% of the records from a table.
32. Write an SQL query to fetch the department that have less than five people in them.
33. Write an SQL query to show all department along with the number of people in there.
34. Write an SQL query to show the last record from a table.
35. Write an SQL query to fetch the first row of a table.
36. Write an SQL query to print the names of employees having the highest salary in each
department.
37. Write an SQL query to fetch three max salaries from a table.
38. Write an SQL salary to fetch three min salaries from a table.
39. Write an SQL query to fetch nth max salaries from a table.
40. Write an SQL query to fetch departments along with the total salaries paid for each of them.
41. Write an SQL query to fetch the names of workers who earn the highest salary
42.
43. Write an SQL query to find the third maximum salary from the “salaries” table without using
the LIMIT clause.
44. Write an SQL query to list the employees who have never been assigned to a department.
45. Write an SQL query to retrieve the employees with the highest salary in each department.
46. Write an SQL query to calculate the median salary for each department.
47. Write an SQL query to find the employees who have the same manager as the employee
with ID 3.
48. Write an SQL query to retrieve the employees who have the highest salary in their respective
department and joined in the last 6 months.
49. Write an SQL query to list the departments with more than 3 employees.
50. Write an SQL query to retrieve the employees with the second-lowest salary.
51. Write an SQL query to find the departments where the highest and lowest salaries differ by
more than $10,000.
52. Write an SQL query to update the salaries of all employees in the “IT” department to be 10%
higher and print records displaying old vs. new salary.

Additional Practice Queries


35. Write an SQL query to calculate the difference in days between the hire dates of each
employee and their manager.
36. Write an SQL query to fetch the names of employees whose salaries match the salary of
employee ID 2 in a different department.

You might also like