【发布时间】:2013-12-17 16:24:54
【问题描述】:
我有两个临时表 temp1 和 temp2(它们是在运行时创建的)。我需要执行“FULL external JOIN”来从两个表中获取数据。但我得到了错误
Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near 'FULL OUTER JOIN cashExtTemp t2
ON t1.code = t2.code'
SELECT * FROM cashIntTemp t1 FULL OUTER JOIN cashExtTemp t2 ON t1.code = t2.code
并且通过此链接Full Outer Join in MySQL 了解到在 MySQL 中不可能进行 FULL OUTER JOIN 并尝试按照链接中给出的方式实现 UNION。因为我使用的是临时表,所以它不起作用,我得到了错误
Error Number: 1137
Can't reopen table: 't1'
这是我的 UNION 查询
SELECT * FROM cashIntTemp t1 LEFT JOIN cashExtTemp t2 ON t1.code = t2.code
UNION
SELECT * FROM cashIntTemp t1 RIGHT JOIN cashExtTemp t2 ON t1.code = t2.code
表中的数据会是这样的 表:cashIntTemp
code qty date
P001 100 2013-11-29
P003 200 2013-11-30
P005 600 2013-11-30
表中的数据会是这样的 表:cashIntTemp
code qty date
P001 110 2013-11-29
P002 250 2013-12-01
P005 650 2013-12-01
我需要一个查询来获取两个表中的所有数据。
我需要这种格式的结果
code qty date code qty date
P001 100 2013-11-29 P001 110 2013-11-29
P002 250 2013-12-01
P003 200 2013-11-29
P005 600 2013-11-29 P005 650 2013-11-29
所以请帮助我。提前致谢。
【问题讨论】:
-
select * from (select * from tbl where someclause) t1 left join ANOTHERTABLE s ON (s.id=t1.id)