我想使用UNION ALL命令合并到表中。然后我想用另一个表INNER JOIN结果。我玩了以下结构,但它不起作用:
(Select * from TableA
UNION ALL
Select * from TableB)
INNER JOIN TableC
ON somekey
答案 0 :(得分:2)
您需要alias UNION ALL
的结果并从中选择
SELECT *
FROM (SELECT * FROM TableA UNION ALL SELECT * FROM TableB) ua
INNER JOIN TableC ON TableC.somekey = ua.SomeKey
答案 1 :(得分:2)
select *
from (Select * from TableA union all Select * from TableB) t1
inner join TableC t2 on t1.somekey=t2.somekey;