0

OK, given the following dataset:

ID , name    , lineManagerKey, lineManagerName
 1 , Joe     , null          , null
 2 , Herbert ,    1          , Joe
 3 , John    ,    1          , Joe
 4 , George  , null          , null
 5 , Paul    , null          , null
 6 , Ringo   , null          , null
 7 , Frank   , null          , null
 8 , Jeff    ,    7          , Frank

I want to return the following:

Manager,Minion
Joe,Herbert
Joe,John
Frank,Jeff

Every way I am thinking of the possible query it seems to want to return multiple rows? Any ideas?

Strawberry
  • 33,750
  • 13
  • 40
  • 57
Steven W
  • 29
  • 4
  • Possible duplicate of [How to create a MySQL hierarchical recursive query](https://stackoverflow.com/questions/20215744/how-to-create-a-mysql-hierarchical-recursive-query) – Raymond Nijland Nov 30 '18 at 16:13
  • Why do you have both lineManagerKey and lineManagerName? It sounds like you have a LineManager table which already maps keys to names? – Lightness Races in Orbit Nov 30 '18 at 16:28
  • You can pretty much ignore the Line Manager Name, but I added it in, in this case so you visualise the data structure better. – Steven W Nov 30 '18 at 16:30

1 Answers1

1
select lineManagerName as Manager,name as Minion from table where lineManagerName is not null;
Reda Meskali
  • 275
  • 3
  • 9