UPDATE没有子查询抛出错误:子查询返回多于1行

时间:2013-09-09 23:02:44

标签: mysql sql sql-update mysql-5.6

有人可以向我解释这个...... :) (使用MySQL 5.6.13)

UPDATE offer SET cosid=1 WHERE id=40;
Query OK, 1 row affected (0.07 sec)
Rows matched: 1  Changed: 1  Warnings: 0

UPDATE offer SET cosid=4 WHERE id=40;
ERROR 1242 (21000): Subquery returns more than 1 row

UPDATE offer SET cosid=5 WHERE id=40;
Query OK, 1 row affected (0.04 sec)
Rows matched: 1  Changed: 1  Warnings: 0

除了四个以外,每个有效索引都被接受:(

这是要约表:

CREATE TABLE offer (
  id               bigint(20) NOT NULL AUTO_INCREMENT, 
  authorid         bigint(20) NOT NULL, 
  offered_designid bigint(20) NOT NULL, 
  cdid             bigint(20), 
  cosid            bigint(20) NOT NULL, 
  PRIMARY KEY (id), 
  UNIQUE INDEX (id)) ENGINE=InnoDB;

有什么建议可能出错吗?

EDITED:这是当前的cos表:

SELECT * FROM cos;
+----+-------------+
| id | offer_state |
+----+-------------+
|  1 | active      |
|  5 | cancelled   |
|  3 | inactive    |
|  4 | realized    |
|  2 | waiting     |
+----+-------------+

5行(0.00秒)

1 个答案:

答案 0 :(得分:3)

正如ypercube在评论中所述,并且您已经确认,触发器是罪魁祸首!