我在尝试实现这一目标时遇到了一些麻烦。以下是我需要做的要点:
UPDATE links SET
link = '$link', rid = $rid, order = $order
WHERE lid = $lid
IF (SELECT COUNT(*) FROM resources WHERE rid = $rid AND (sid = $sid OR sid IS NULL) AND types IS NULL) == 1;
所以基本上,当且仅当资源表中的资源与站点(sid)相关联或者没有与任何特定站点相关联且类型为null时,我想运行UPDATE。
我想我可以运行一个PHP条件,但如果我可以用一个查询执行此操作会更好。有可能吗?
Thansk提前这么多!
答案 0 :(得分:5)
UPDATE links
SET link = '$link', rid = $rid, order = $order
WHERE lid = $lid
and (SELECT COUNT(*)
FROM resources
WHERE rid = $rid
AND (sid = $sid OR sid IS NULL)
AND types IS NULL) = 1;