Tuesday, 10 September 2013

MySQL - Do I need a loop or is their an easier way here

MySQL - Do I need a loop or is their an easier way here

So here's the deal.
I have a table called employees that contains the columns.
ID | Name | Salary | Department_id | Boss_id
So all employees are listed in this no matter where they're bosses or not.
If someone is not a boss then their value for Boss id will be NULL.
The aim is, to figure out if any employees earn more than their respective
bosses and by respective I mean, from the same department.
I've been working on this trying to figure it out and I'm not sure if I
need a loop to loop through all the departments or it there is an easy
way.
Really appreciate some help here.

No comments:

Post a Comment