• + 0 comments

    MySQL - simplest solution using join

    select s1.name
    from Students s1
    join Friends f1
    on s1.ID = f1.ID
    join Packages p1
    on f1.Friend_ID = p1.ID
    join Packages p2
    on f1.ID = p2.ID
    where p1.salary > p2.salary
    order by p1.salary