#1241 - 操作数应包含 1 列更新案例

#1241 - Operand should contain 1 column(s) update case

我尝试此操作时一直出现此错误:

update table1
set value1="apple"
where id IN (
select * table1_table2 where value2= "juice"
)

您不能 select 子句中的多列

update table1
set value1="apple"
where id IN (
select id from table1_table2 where value2= "juice"
)

正如已经指出的那样,问题出在使用 SELECT * 的子查询中,它选择了两个或更多列。我建议在这里使用 EXISTS 逻辑:

UPDATE table1 t1
SET value1 = 'apple'
WHERE EXISTS (SELECT 1 FROM table1_table2 t12
              WHERE t12.some_id = t1.id AND t2.value = 'juice');

此答案假定您要与 table1#id 进行比较的 table1_table2 中的列称为 some_id