我需要运行SQL查询
UPDATE function
SET active = 0
WHERE unitRef IN
(SELECT unitRef
FROM project_unit
WHERE projectRef = 1);
当我运行此查询时,phpmyadmin表示0行会受到影响。 但是当我独立运行以下代码时:
SELECT unitRef
FROM project_unit
WHERE projectRef = 1
它返回的行数超过1行。
我做错了吗?
答案 0 :(得分:3)
这两种结构并不相同。相反,试试这个
SELECT *
FROM function
WHERE unitRef in
(select
unitRef
from project_unit
where projectRef=1);
答案 1 :(得分:1)
你错过了'SET'关键字......
UPDATE `function`
SET active = 0
WHERE unitRef IN (SELECT unitRef FROM project_unit WHERE projectRef = 1);
虽然这会给你一个错误,不只是说0 row(s) affected
。子查询返回的值是否存在于表unitRef
的字段function
中?
答案 2 :(得分:0)
用于MS SQL Server:
UPDATE [function]
SET active=0
WHERE unitRef in
(SELECT
pu.unitRef
FROM project_unit as pu
WHERE pu.projectRef=1);