Reputation: 41
Table1
StaffId int primary key,
StaffName nvarchar(150)
Table2
DoctorIdRef int FOREIGN KEY REFERENCES Table1(StaffId),
AdminIdRef int FOREIGN KEY REFERENCES Table1(StaffId),
This is my two tables structure and I want to select data like
select DoctorIdRef, DoctorName, AdminIdRef, AdminName
Upvotes: 0
Views: 35
Reputation: 2560
select DoctorIdRef, Doctor.StaffName DoctorName, AdminIdRef, Adminr.StaffName AdminName
from Table2
left join Table1 as Doctor on Doctor.StaffId = Table2.DoctorIdRef
left join Table1 as Adminr on Adminr.StaffId = Table2.AdminIdRef
Upvotes: 1