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 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...
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.