Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql SQL将表的列与另一个表的行连接起来_Mysql_Sql - Fatal编程技术网

Mysql SQL将表的列与另一个表的行连接起来

Mysql SQL将表的列与另一个表的行连接起来,mysql,sql,Mysql,Sql,我有一个表,其中的列有Manager、TL、Architect等,这些列用它们的emp_id填充 Group Manager TL Architect 1 256 455 339 另一个雇员主表 Emp_id Name Address 256 Rick Bombay 455 Dennis Madras 339 Harry Denver 我如何连接这两个表以获得经理、TL和架构师的详细信息,包括组、名称、地址

我有一个表,其中的列有Manager、TL、Architect等,这些列用它们的emp_id填充

Group   Manager   TL    Architect

1       256    455     339
另一个雇员主表

Emp_id  Name   Address

256     Rick    Bombay
455     Dennis  Madras
339     Harry   Denver
我如何连接这两个表以获得经理、TL和架构师的详细信息,包括组、名称、地址emp_id等


我知道桌子的设计很差,但我无法控制它。它们是旧表,我必须使用它们。

注意表标识符周围的方括号是Microsoft SQL Server支持的语法,但不支持MySQL。@BillKarwin没有注意到MySQL标记。感谢捕获。请注意,表标识符周围的方括号是Microsoft SQL Server支持的语法,但不支持MySQL。@BillKarwin没有注意到MySQL标记。谢谢你接电话。我会先用UNION。我会先用UNION。
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