Hi @Kosovari_ ,
Please refer below example and check whether it is helpful to you.
--create tables
create table Departments
(DeptID int primary key,
DeptName varchar(20) )
create table Supervisor
(SuperVisorID int primary key,
FirstName varchar(20),
LastName varchar(20),
DeptID int FOREIGN KEY REFERENCES Departments(DeptID))
create table Employees
(EmployeeID int primary key,
SuperVisorID int FOREIGN KEY REFERENCES Supervisor(SuperVisorID))
--insert sample data
insert into Departments values
(101,'Develop'),
(102,'HR sales')
insert into Supervisor values
(20001,'Jerry','O',101),
(20002,'Lim','P',102),
(20003,'Kim','Q',102)
insert into Employees values
(10001,20001),
(10002,20002),
(10003,20003)
--query
select a.*,b.DeptName,c.EmployeeID
from Supervisor a
left join Departments b on a.DeptID=b.DeptID
left join Employees c on a.SuperVisorID=c.SuperVisorID
where DeptName ='HR sales'
Output:
SuperVisorID FirstName LastName DeptID DeptName EmployeeID
20002 Lim P 102 HR sales 10002
20003 Kim Q 102 HR sales 10003
Best regards,
Melissa
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.