John
John

Reputation: 750

SQL join columns of table with row of another table

I have a table with columns as Manager, TL, Architect etc which are populated with their emp_ids.

Group   Manager   TL    Architect

1       256    455     339

Another employee master table.

Emp_id  Name   Address

256     Rick    Bombay
455     Dennis  Madras
339     Harry   Denver

How do I join these two tables to get Manager, TL and Architect details with group, name, address emp_id etc.

I know that the table design is poor but I have no control on it. They are legacy tables and I have to work with them.

Upvotes: 0

Views: 420

Answers (1)

Metaphor
Metaphor

Reputation: 6395

SELECT
    g.GroupId
    ,mgr.Name AS Manager
    ,tl.Name AS TL
    ,arc.Name AS Architect
FROM Groups g
LEFT JOIN Employee mgr ON mgr.EmpId = g.ManagerId
LEFT JOIN Employee tl ON tl.EmpId = g.TlId
LEFT JOIN Employee arc ON ar.EmpId = g.ArchitectId

Upvotes: 2

Related Questions