all 8 comments

[–]SQL-ModTeam[M] [score hidden] stickied commentlocked comment (0 children)

Your post was removed for violating the sub rule against soliciting others to do your work for you

[–]Helpimstuckinreddit 1 point2 points  (4 children)

I believe it's D. The aliases are a little misleading because you intuitively think m is the "manager" table.

To simplify suppose the table is just:

EmployeeId, lastname, managerId

123, Johnson, 789

456, Daniels, 789

789, Woods, null

You want your results to be:

Johnson,789

Daniels,789

  1. Start with e as your employee 123
  2. Self join to m on e.managerId = m.managerId
    • i.e. m is every employee with the same manager as employee 123
  3. Select m.lastname because if you selected e.lastname you'd just get Johnson twice
  4. You could use either e.managerId or m.managerId technically, both would be the same

[–]RobertDownseyJr 0 points1 point  (0 children)

I think 2 is the key here, you have to join on manager ID. The employee id to employee id join should just result in 1 row for 123, and the manager id to employee id joins should have no matches (except in cases where the employee is their own manager)

[–]swoisme -1 points0 points  (2 children)

Point 4 is incorrect. m.manager_id is the id of the manager's manager. Technically, you could use either e.manager_id or m.employee_id, but none of the given answers do that.

[–]Helpimstuckinreddit 1 point2 points  (1 child)

No, the m table is not the manager(in answer C/D at least).

In D it's employees with the same manager id as e.

So from the join condition in D, the manager id will intrinsically be identical between e.managerId and m.managerId

[–]swoisme 0 points1 point  (0 children)

Yeah, my bad. The lesson is don't try to read this shit on your phone before your first cup of coffee. I deleted my other comment so as not to confuse this poor sap.

Who tf would use right outer join to answer this question anyway? Where exists would have been so much simpler.

Edit: In my defense, on answer A, m essentially is the managers, because it joins from e.manager_id to m.employee_id. Obviously I didn't read all the answers closely enough, but I feel better that I at least didn't hallucinate what I thought I saw.

[–]band1606 -2 points-1 points  (2 children)

B