在MySql中使用CTE进行联合和左联接的正确语法是什么?
示例:
With Test As (
Select * from thistle
),
Select * from table1 t1
Union all
Select * from table2 t2
Left Join test ts
On t.userID = t1.userID
答案 0 :(得分:0)
使用两个CTE编写查询可能是最清晰的:
WITH Test AS (
SELECT *
FROM thistle
),
T1T2 AS (
SELECT * FROM table1 t1
UNION ALL
SELECT * FROM table2 t2
)
SELECT *
FROM T1T2
LEFT JOIN Test ON T1T2.userID = Test.userID