情景:
使用sql语句处理某些内容,执行到某个语句时,Mysql报错误
报错:
Operand should contain 1 column
理解:
需要有1个数据列。
错误的sql:
update table1 set content= 'cd is a good boy'
where id in (
select * from(
select * from table1 where type in(1,2,3) order by id desc limit 100
)as cd
)
原因:
“where id in(~~~)”,子查询使用了(select * ~~),则子查询得到的是不止一列的数据记录 ,而 where id in(~~~) 需要的条件数据是一个列
解决:
把 where id in(~~) 括号内的第一层子查询的 “*” 改成 “id”
update table1 set content= 'cd is a good boy'
where id in (
select id from(
select * from table1 where type in(1,2,3) order by id desc limit 100
)as cd
)