SQL执行delete in条件语句时,出现“[Err] 1241 - Operand should contain 1 column(s)”错误,在Eclipse中也报了如下错误:
### Error updating database. Cause: java.sql.SQLException: Operand should contain 1 column(s)
### The error may involve com.voavoice.english.dao.ToparticleMapper.deleteByMinTime-Inline
### The error occurred while setting parameters
### SQL: delete from toparticle where id in (SELECT id,MIN(top_time) FROM `toparticle` where article_type= ?)
### Cause: java.sql.SQLException: Operand should contain 1 column(s)
; bad SQL grammar []; nested exception is java.sql.SQLException: Operand should contain 1 column(s)
错误解析:
小编的in条件语句是这样的,如下:
delete from toparticle where id in (SELECT id,MIN(top_time) FROM `toparticle` where article_type='666666')
出现这样的而错误,是因为in条件后面有多个字段造成的,因为in条件只能存在一个字段,不可能混杂使用,因此得改成类似如下这样,去掉一个字段即可:
delete from toparticle where id in (SELECT id FROM `toparticle` where article_type='666666')