一聚教程网:一个值得你收藏的教程网站

热门教程

Mysql错误Operand should contain * column解决办法

时间:2022-11-14 23:37:00 编辑:袖梨 来源:一聚教程网

使用了sql语句处理某些内容。当执行某个语句时,Mysql报错误:Operand should contain 1 column

字面意思是,需要有1个数据列。

我的sql语句类似这样:

update cdtable set cdcontent=’cd is a good boy’ where id in(

select * from(

select * from cdtable where cdtype in(1,2,3) order by id desc limit 100

)as cd

)

虽然错误的字面意思是缺少列,但是究竟是哪里缺少了列呢?

经过测试,发现是在加上最外层的sql语句之后报的错

仔细看了一下语句,发现在上面语句的蓝色部分“where id in(~~~)”,子查询使用了(select * ~~)子查询得到的是不止一列的数据记录

而很明显,where id in 需要的条件数据是一个列,问题就发生在这里啦

解决的方法是:把where id in(~~)括号内的第一层子查询的“*”改成“id”即可,改后的句子就像:

update cdtable set cdcontent=’cd is a good boy’ where id in(

select id from(

select * from cdtable where cdtype in(1,2,3) order by id desc limit 100

)as cd

)

热门栏目