For these exercises, we use the Employees Database presented at the end of Chapt
ID: 3702533 • Letter: F
Question
For these exercises, we use the Employees Database presented at the end of Chapter 1. Answer each question with a single SQL statement. Your query must work for any set of data in the Employees Database, not just the set of data we provide.
8. For each employee ID, find the last name of all employees making more money than that employee. Solve it two ways: 1) using only WHERE-based join (i.e., no INNER/OUTER/CROSS JOIN) and 2) using some form of JOIN.
24 Chapter I:Databasks projects projectd deparmenls code managerid subdeplof description startdate encdate revenue workson empore edi assignedime employeeld firstname lastname deplcode salary Figure 1.5: Schema for the Imployees DatabaseExplanation / Answer
Solution:
Note: The source of money for the employee is salary, which is present in the employee table, this means that only one table is enough to extract the required information, so there will be only one query since we are not joining any tables here.
Query:
SELECT lastname FROM employees e1, employees e2 WHERE e1.salary>e2.salary GROUP BY employeeID
Using JOIN:
SELECT lastname FROM employees e1 INNER JOIN employees e2 ON e1.employeeiD= e2.employeeiD WHERE e1.salary>e2.salary GROUP BY employeeID
I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)