来自另一个表的更新表上的SQL错误

时间:2018-03-27 10:15:34

标签: sql sql-update

我正在尝试从另一个表更新数据库表的一列。

但总是得到同样的错误:

#1064 - 您的SQL语法出错;查看与您的MySQL服务器版本对应的手册,以便在'FROM wp_popularpostsdata T1 INNER JOIN wp_top_ten T2 ON T1.postid = T2.postnumbe'第11行附近使用正确的语法

我发现一篇帖子谈到了错误1064,但没有帮助我。

我尝试过这些代码:

UPDATE A
SET A.pageviews = B.cntaccess
FROM wp_popularpostsdata A INNER JOIN wp_top_ten B ON A.postid = B.postnumber

UPDATE a
SET a.pageviews = b.cntaccess
FROM wp_popularpostsdata a JOIN wp_top_ten b ON a.postid = b.postnumber

UPDATE T1
SET T1.pageviews = T2.cntaccess
FROM wp_popularpostsdata T1 INNER JOIN wp_top_ten T2 ON T1.postid = T2.postnumber
WHERE 1;

请帮帮我吗?

2 个答案:

答案 0 :(得分:0)

我认为您正在使用MySQL,根据查询中的更正:

UPDATE wp_popularpostsdata A
JOIN wp_top_ten B ON A.postid = B.postnumber
SET A.pageviews = B.cntaccess

UPDATE wp_popularpostsdata a
JOIN wp_top_ten b ON a.postid = b.postnumber
SET a.pageviews = b.cntaccess


UPDATE wp_popularpostsdata T1
JOIN wp_top_ten T2 ON T1.postid = T2.postnumber
SET T1.pageviews = T2.cntaccess
WHERE 1;

对于常规更新加入:

<强> 1。 MYSQL

UPDATE TABLEA a 
JOIN TABLEB b ON a.join_colA = b.join_colB  
SET a.columnToUpdate = [something]

2.SQL SERVER或MSSSQL

UPDATE A
SET foo = B.bar
FROM TableA A
JOIN TableB B
    ON A.col1 = B.colx
WHERE ...

答案 1 :(得分:0)

UPDATE wp_popularpostsdata A INNER JOIN wp_top_ten B ON A.postid = B.postnumber
SET A.pageviews = B.cntaccess

UPDATE wp_popularpostsdata a JOIN wp_top_ten b ON a.postid = b.postnumber
SET a.pageviews = b.cntaccess

UPDATE wp_popularpostsdata T1 INNER JOIN wp_top_ten T2 ON T1.postid = T2.postnumber
SET T1.pageviews = T2.cntaccess
WHERE 1;