SELECT E.NAME ,E.COLUMN1,E.COLUMN2,E.COLUMN3,E.COLUMN4 FROM (
SELCT NAME FROM A
UNION
SELCT NAME FROM B
UNION
SELCT NAME FROM C
UNION
SELCT NAME FROM D) E
GROUP BY E.NAME
SELECTA.Name,
A.COLUMN1,
B.COLUMN2,
C.COLUMN3,
D.COLUMN4
FROM
A LEFT JOIN B
ON ( A.NAME = B.NAME )
LEFT JOIN C
ON ( A.NAME = C.NAME )
LEFT JOIN D
ON ( A.NAME = D.NAME )
UNION
SELECT
B.Name,
A.COLUMN1,
B.COLUMN2,
C.COLUMN3,
D.COLUMN4
FROM
B LEFT JOIN A
ON ( A.NAME = B.NAME )
LEFT JOIN C
ON ( B.NAME = C.NAME )
LEFT JOIN D
ON ( B.NAME = D.NAME )
UNION
SELECT
C.Name,
A.COLUMN1,
B.COLUMN2,
C.COLUMN3,
D.COLUMN4
FROM
C LEFT JOIN A
ON ( C.NAME = A.NAME )
LEFT JOIN B
ON ( B.NAME = C.NAME )
LEFT JOIN D
ON ( C.NAME = D.NAME )
UNION
SELECT
D.Name,
A.COLUMN1,
B.COLUMN2,
C.COLUMN3,
D.COLUMN4
FROM
D LEFT JOIN A
ON ( D.NAME = A.NAME )
LEFT JOIN B
ON ( B.NAME = D.NAME )
LEFT JOIN C
ON ( C.NAME = D.NAME )
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)