INNER JOIN THREE TABLES (SSMS 19)

Kosovari_ 81 Reputation points
2021-10-04T23:07:46.507+00:00

0 (Rows) affected how to fix it , To shown to me examples text HR SALES ??

SSMS (2019) EXPRESS

I have three tables at SQL SERVER 2019 described below:

Table DEPARTMENTS : Columns DeptID , DeptName

Table EMPLOYEES : Columns : EmployeeID , SupervisorID .

Table SUPERVISOR : Columns : FirstName, LastName, SupervisorID, DeptID .

THANK YOU DEAREST FRIENDS . YOUNG KOSOVAR CITIZEN FROM KOSOVO ..

SQL Server Integration Services
SQL Server Integration Services
A Microsoft platform for building enterprise-level data integration and data transformations solutions.
2,702 questions
Developer technologies Transact-SQL
0 comments No comments
{count} votes

Accepted answer
  1. MelissaMa-MSFT 24,221 Reputation points
    2021-10-05T01:58:13.213+00:00

    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.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.