错误代码:1222.使用的SELECT语句具有不同的列数 [英] Error Code: 1222. The used SELECT statements have a different number of columns
问题描述
我尝试了一些包含连接的语句,但是还不能将来自其他三个MySQL表的数据插入到一个表中.在最后一次尝试时,我收到此错误:错误代码:1222.使用的SELECT语句具有不同的列数 请参阅以下有关我输入的查询的信息. (我是编码的新手,所以我还是MySQL的新手.感谢您的帮助.谢谢.)
I'v tried a few statements including joins, but have not been able to insert data from three other MySQL tables into one. On my last attempt, I received this error: Error Code: 1222. The used SELECT statements have a different number of columns Please see below for the query I entered. (I'm new to coding, so I'm still pretty much a novice with MySQL. Any help is appreciated. Thanks.)
INSERT INTO cases (person_id, last_name, first_name, date_applied)
SELECT person_id, last_name, first_name,
date_applied FROM person UNION SELECT (program_name) FROM program
UNION SELECT (status) FROM casestatus
推荐答案
UNION
关键字之前的SELECT语句选择4列,而UNION
关键字之后的SELECT语句仅选择1列.您不能用不同的列数来构建UNION
,这就是您收到有关列数不同"的错误消息的原因.
The SELECT statement before the UNION
keyword selects 4 columns but the SELECT statement after the UNION
keyword selects only 1 column. You cannot build a UNION
with different number of columns, thats the reason you get this error message about "different number of columns".
这篇关于错误代码:1222.使用的SELECT语句具有不同的列数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!