错误代码:1222.使用的SELECT语句具有不同的列数 [英] Error Code: 1222. The used SELECT statements have a different number of columns

查看:208
本文介绍了错误代码:1222.使用的SELECT语句具有不同的列数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了一些包含连接的语句,但是还不能将来自其他三个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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆