0

Mysql 错误:从两个现有表创建新表时出现 1222。这是我的 sql 语句,用于从两个现有表创建一个新表。请帮助我找到解决此问题的方法,谢谢

CREATE TABLE insurance_db.new_insurance 
SELECT * FROM insurance_db.auto_insurance
UNION all
SELECT * FROM insurance_db.home_insurance;  
4

2 回答 2

0

试试这个方法

CREATE TABLE insurance_db.new_insurance 
As (SELECT col1, col2,.... FROM insurance_db.auto_insurance, insurance_db.home_insurance);
于 2014-08-25T06:42:24.573 回答
0

您似乎试图将SELECTs 与不同的列数结合起来。

例如:

SELECT 1     -- one column
UNION ALL
SELECT 1, 2  -- two colums

导致此错误:

Error Code: 1222. The used SELECT statements have a different number of columns

尝试对两个选择使用确定的 columnt-list:

CREATE TABLE insurance_db.new_insurance 
SELECT
    col1, col2, col3 ...
FROM
    insurance_db.auto_insurance
UNION ALL
SELECT
    col1, col2, col3 ...
FROM
    insurance_db.home_insurance; 
于 2014-08-25T07:02:00.303 回答