我正在尝试从mysql中的两个表中访问完整数据,然后从结果集中查找列的不同值。尝试使用嵌套查询,如下所示: -
Select distinct s.BlockName
from (SELECT *
FROM constucted
LEFT JOIN required ON constucted.BlockName = required.BlockName
UNION
SELECT *
FROM constucted
RIGHT JOIN required ON constucted.BlockName = required.BlockName
) s
如Stackoverflow Reference中所述 并尝试使用with关键字如下: -
WITH CTE
AS
(
SELECT *
FROM constucted
LEFT JOIN required ON constucted.BlockName = required.BlockName
UNION
SELECT *
FROM constucted
RIGHT JOIN required ON constucted.BlockName = required.BlockName
)
SELECT DISTINCT BlockName
FROM CTE
但无法找到BlockName列无法为其编写查询的明确值。
答案 0 :(得分:1)
您的查询似乎更简单地写为:
select BlockName
from constructed
union -- intentional to remove duplicates
select BlockName
from required;