0

当我尝试以下查询时:

UPDATE cache_implementation
SET parent_through_compared_id = ncp.nid, parent_through_feature_id = nfp.nid
FROM cache_implementation n
INNER JOIN cache_compare nc ON n.compared_id = nc.nid
INNER JOIN cache_implementation ncp ON (nc.nid = ncp.compared_id AND n.feature_id = ncp.feature_id)
INNER JOIN cache_feature nf ON n.feature_id = nf.nid
INNER JOIN cache_implementation nfp ON (nf.nid = nfp.feature_id AND n.compared_id = nfp.compared_id)

我有以下错误:您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 3 行的“FROM cache_implementation n INNER JOIN cache_compare nc ON n.compared_id = nc”附近使用正确的语法

通过此查询,我尝试通过进行批量更新查询来更新具有位于其他表中的值的两个字段。

4

2 回答 2

1

在 MySQL 多表更新语句中,SET子句跟在表引用之后。(这与其他数据库中使用的语法不同。)

要修复您的语句,请删除第一行,将带有 SET 的行移至底部,使用表别名限定列引用,然后更改FROMUPDATE. 瞧。

UPDATEcache_implementation
FROM
cache_implementation n
INNER JOIN……
INNER JOIN_

SET n.col = expr, n.col2 = expr

此处记录的多表更新语法:http://dev.mysql.com/doc/refman/5.5/en/update.html

于 2013-07-26T16:29:54.417 回答
1

您正在使用TSQL. 这是为MySQL.

UPDATE cache_implementation n
       INNER JOIN cache_compare nc 
             ON n.compared_id = nc.nid
       INNER JOIN cache_implementation ncp 
             ON (nc.nid = ncp.compared_id AND n.feature_id = ncp.feature_id)
       INNER JOIN cache_feature nf 
             ON n.feature_id = nf.nid
       INNER JOIN cache_implementation nfp 
             ON (nf.nid = nfp.feature_id AND n.compared_id = nfp.compared_id)
SET    parent_through_compared_id = ncp.nid, parent_through_feature_id = nfp.nid
于 2013-07-26T16:20:40.333 回答