错误前提
UPDATE qipa_country SET city_id = ( SELECT id FROM qipa_city WHERE city_name =‘临高县’) WHERE NAME = ‘临高县’;
报错:
1242 Subquery returns more than 1 row
分析原因
查询SQL语句时,其中有个字段是从另一张表里获取的值,作为另一个表的值
查询出num是多条数据,而外层查询结果是要求num为一条数据
解决方案
限制获取值的条数 或删除多余数据后在执行
UPDATE qipa_country SET city_id = ( SELECT id FROM qipa_city WHERE city_name =‘临高县’ limit 1) WHERE NAME = ‘临高县’;