您好,欢迎访问一九零五行业门户网

如果用于在 UPDATE 语句的 SET 子句中分配新值的子查询返回多行,MySQL 将返回什么?

在这种情况下,mysql 将返回一条错误消息,因为我们知道,如果使用子查询在 update 语句的 set 子句中分配新值,那么它必须为更新表中匹配的每一行返回一行where 子句。
示例mysql> insert into info(id, remarks) values(5,'average');query ok, 1 row affected (0.06 sec)mysql> select * from info;+------+-----------+| id | remarks |+------+-----------+| 1 | good || 2 | good || 3 | excellent || 4 | average || 5 | best || 5 | average |+------+-----------+6 rows in set (0.00 sec)
正如我们在上面看到的,“info”表有两行 id = 5,因此当我们在子查询中使用它时,它将返回多行,因此 mysql 将返回一条错误消息,如下 -mysql> update student set grade = (select remarks from info where info.id = student.id) where id = 5;error 1242 (21000): subquery returns more than 1 row
以上就是如果用于在 update 语句的 set 子句中分配新值的子查询返回多行,mysql 将返回什么?的详细内容。
其它类似信息

推荐信息