0

Hi i have two tables Person (IDPerson, name, surname) and Teacher(IdPerson, superior(witch is in idPerson)) and i have to create MSSQL query which will give me Teacher name, surname and his superior name and surname. I have no Idea how to add second select to query:

Select os.name+ ' ' + os.surname as 'teacher', 
osb.name+ ' ' + osb.surname as 'superior' from Person os
inner join Teacher d on os.IdPerson=d.IdPerson
inner join Teacher dt on osb.IdOsoba=d.Podlega; (how to add second Person osb ?)

I know it's wrong but i have no idea how to do it correct. Please help.

  • I got this: select os.imie, os.nazwisko, p.przedmiot, oc.ocena from Osoba os inner join Ocena oc on oc.IdStudent=os.IdOsoba inner join Przedmiot p on oc.IdPrzedmiot=p.IdPrzedmiot order by p.Przedmiot, oc.Ocena desc; – Jakub25 May 10 '20 at 15:59
  • Does this answer your question? [Self Join to get employee manager name](https://stackoverflow.com/questions/11427300/self-join-to-get-employee-manager-name) – Suraj Kumar May 10 '20 at 16:00

2 Answers2

0

I try this one:

Select os.imie+ ' ' + os.nazwisko as 'dydaktyk' from osoba os
inner join Dydaktyk d on os.IdOsoba=d.IdOsoba union all
Select osb.imie +' '+osb.nazwisko as 'przelozony' from Osoba osb  
inner join Dydaktyk dt on osb.IdOsoba=dt.Podlega

and it's closer, but i have all date in one column and i need it i two, plus not all teacher have superior, so i need to do it in some way with join left... ehhh...

0

ok this one work for me :)

Select o.name + ' ' + o.surname as 'techer', c.name  + ' '+ c.surname as 'superior'
from person o
Join teacher b on o.Idperson = b.Idperson
left Join person c on b.Podlega = c.idperson