无法使用 UNION ALL 创建新表 [英] Can't create a new table with UNION ALL
本文介绍了无法使用 UNION ALL 创建新表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
SQL 执行这段代码(t1 和 t2 结构相同)
SQL executes this piece of code (t1 and t2 have identical structure)
SELECT * FROM `t1` UNION ALL SELECT * FROM `t2`
但不是这个:
CREATE TABLE `test` AS (
SELECT * FROM `prospects-non-clients-valid-quote-images-solo`
UNION ALL
SELECT * FROM `prospects-non-clients-valid-quote-images-duet` )
我收到以下错误消息:
"1064 - 你的 SQL 语法有错误;检查手册对应于您的 MySQL 服务器版本以使用正确的语法在第 3 行
"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 'UNION ALL SELECT * FROM
t2
)' at line 3
我错过了什么?感谢您的帮助!
What am I missing? Thank you for your help!
推荐答案
假设 UNION ALL 有效,在外面使用 SELECT * from
:
Assuming the UNION ALL works, use a SELECT * from
outside:
CREATE TABLE `test` AS select * from (
SELECT * FROM `prospects-non-clients-valid-quote-images-solo`
UNION ALL
SELECT * FROM `prospects-non-clients-valid-quote-images-duet`) t
我建议您在查询中明确指定列名,而不是 *
,因为表模式十会随时间变化.
I'd advise you to explicitly specify column names in the query instead of *
as the table schemas ten to change with time.
这篇关于无法使用 UNION ALL 创建新表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文