SQL (Part 1)
SQL (Part 1)
Select employees first name, last name, job_id and salary whose first name
starts with alphabet S.
2. Write a query to select employee with the highest salary.
3. Select employee with the second highest salary.
4. Fetch employees with 2nd or 3rd highest salary.
5. Write a query to select employees and their corresponding managers and their
salaries.
6. Write a query to show count of employees under each manager in descending order.
7. Find the count of employees in each department.
8. Get the count of employees hired year wise.
9. Find the salary range of employees.
10. Write a query to divide people into three groups based on their salaries.
11. Select the employees whose first_name contains “an”.
12. Select employee first name and the corresponding phone number in the format (_
_ _)-(_ _ _)-(_ _ _ _).
13. Find the employees who joined in August, 1994.
14. Write an SQL query to display employees who earn more than the average salary
in that company.
15. Find the maximum salary from each department.
16. Write a SQL query to display the 5 least earning employees.
17. Find the employees hired in the 80s.
18. Display the employees first name and the name in reverse order.
19. Find the employees who joined the company after 15th of the month.
20. Display the managers and the reporting employees who work in different
departments.
21. Write an SQL query to fetch nth max salaries from a table.
22. Write an SQL query to fetch departments along with the total salaries paid for
each of them.
23. Write an SQL query to fetch the names of workers who earn the highest salary.
24. Write an SQL query to fetch three min salaries from a table.
25. Write an SQL query to fetch three max salaries from a table.
26. Write an SQL query to print the names of employees having the highest salary in
each department.
27. Write an SQL query to fetch the last five records from a table.
28. Write an SQL query to show the last record from a table.
29. Write an SQL query to show all departments along with the number of people in
there.
30. Write an SQL query to fetch the departments that have less than five people in
them.
31. Write an SQL query to fetch the first 50% of records from a table.
32. Write an SQL query to fetch intersecting records of two tables.
33. Write an SQL query to show one row twice in the results from a table.
34. Write an SQL query to show the second-highest salary from a table.
35. Write an SQL query to fetch the list of employees with the same salary.
36. Write an SQL query to determine the 5th highest salary without using the TOP or
limit method.
37. Write an SQL query to determine the nth (say n=5) highest salary from a table.
38. Write an SQL query to show the top n (say 10) records of a table.
39. Write an SQL query to show the current date and time.
40. Write an SQL query to show records from one table that another table does not
have.
41. Write an SQL query to fetch intersecting records of two tables.
42. Write an SQL query to fetch duplicate records having matching data in some
fields of a table.
43. Write an SQL query to print details of the Workers who are also Managers.
44. Write an SQL query to fetch the number of workers for each department in
descending order.
45. Write an SQL query to fetch worker names with salaries >= 50000 and <= 100000.
46. Write an SQL query that fetches the unique values of DEPARTMENT from the Worker
table and prints its length.
47. Write an SQL query to print details of workers excluding first names, “Vipul”
and “Satish” from the Worker table.
48. Write an SQL query to print details of the Workers whose FIRST_NAME contains
‘a’.
49. Write an SQL query to print details of the Workers whose FIRST_NAME ends with
‘h’ and contains six alphabets.
50. Write an SQL query to print details of the Workers whose FIRST_NAME ends with
‘a’.