You are given three tables: Students, Friends and Packages. Students contains two columns: ID and Name. Friends contains two columns: ID and Friend_ID (ID of the ONLY best friend). Packages contains two columns: ID and Salary (offered salary in $ thousands per month).
1) Write a query to output the names of those students whose best friends got offered a higher salary than them.
2) Names must be ordered by the salary amount offered to the best friends.
3) It is guaranteed that no two students got same salary offer.
Sample Output
Samantha
Julia
Scarlet
SELECT s.name
FROM students s
INNER JOIN packages p1 ON s.id = p1.id --ID/NAME/SALARY
INNER JOIN friends f ON s.id = f.id --ID/NAME/SALARY/FRIEND_ID
INNER JOIN packages p2 ON f.friend_id = p2.id --ID/NAME/SALARY/FRIEND_ID/FRIEND_SALARY
WHERE p1.salary < p2.salary
ORDER BY p2.salary