Skip to content

Microsoft SMSS – Joining tables on t2.primary key = t1.foreign_key

I need to join two tables together to create a table with columns for employee id, employee name and their boss’ name.

The ‘hier’ table

Hierarchy table

The ’employees’ table

Employees table

The query I wrote is almost working, putting an employee name in the right spot, but not the right employee:

Which outputs:

The table I'm left with

I need to have each person’s boss to have the right name, and in the case of Big Boss, ‘N/A’. Like so:

Desired outcome

Advertisement

Answer

You need a self join with Employee table

User contributions licensed under: CC BY-SA
4 People found this is helpful