我需要一些帮助,我有这个SQL选择:
SELECT *
FROM 'gknwcrpostmeta'
WHERE 'meta_key' LIKE '_fgd2wp_old_node_id'
AND 'meta_value' IN ( SELECT 'object_id'
FROM 'gknwcrterm_relationships'
WHERE 'object_id' = 'meta_value')
工作正常。
现在我想更新 - 找到了什么选择,所以我写了这个查询:
UPDATE 'gknwcrpostmeta'
SET 'meta_key' = 'sac_locked', 'meta_value' = 'logged in'
FROM 'gknwcrpostmeta'
WHERE 'meta_key' LIKE '_fgd2wp_old_node_id'
AND 'meta_value' IN ( SELECT 'object_id'
FROM 'gknwcrterm_relationships'
WHERE 'object_id' = 'meta_value')
模拟查询正常,但实际查询返回:
#1064 - “FROM”gknwcrpostmeta'WHERE'meta_key'LIKE'_fgd2wp_old_node_id'和'meta_valu'在第3行附近的句法出错了
有什么建议吗?
答案 0 :(得分:0)
这在我的数据库中对我有用。我刚用你的名字替换了表名。
UPDATE EmploymentAssignment
SET approver = 1
FROM EmploymentAssignment ea INNER JOIN ( SELECT personID , schoolID FROM EmploymentAssignment WHERE personID LIKE '%75' AND schoolID IN ( 2,3,4) ) t on ea.personID = t.personID AND ea.schoolID = t.schoolID
所以翻译成你的看起来像:
UPDATE `gknwcrpostmeta`
SET `meta_key` = 'sac_locked', `meta_value` = 'logged in'
FROM `gknwcrpostmeta` a INNER JOIN (SELECT * FROM `gknwcrpostmeta` WHERE `meta_key` LIKE '_fgd2wp_old_node_id' AND `meta_value` IN ( SELECT `object_id` FROM `gknwcrterm_relationships` WHERE `object_id` = `meta_value`)) t on a.`meta_key` = t.`meta_key` AND a.`meta_value` = t.`meta_value`
希望这会有所帮助