SQL语法错误:' FROM table_A INNER JOIN table_B ON table_A.name = table_B.name'第1行

时间:2017-03-10 19:56:55

标签: mysql sql

我有一个错误说"您的SQL语法有错误;查看与您的MySQL服务器版本相对应的手册,以便在#table; FROM table_A INNER JOIN table_B ON table_A.name = table_B.name'附近使用正确的语法。在第1行"

sql查询是:

$sql="UPDATE table_A SET table_A.quantity = table_A.quantity -  
table_B.quantity FROM table_A INNER JOIN table_B ON table_A.name = table_B.name 
WHERE table_B.status = 'APPROVED'";

请帮我解决这个错误。谢谢。

2 个答案:

答案 0 :(得分:0)

" INNER"应该是" INNER JOIN"

我认为你还必须拿出" table_A"来自" SET quantity"

 $sql="UPDATE table_A SET quantity = table_A.quantity -  
    table_B.quantity FROM table_A INNER JOIN table_B ON table_A.name = table_B.name 
    WHERE table_B.status = 'APPROVED'";

答案 1 :(得分:0)

您有语法错误。

使用UPDATE更正INNER JOIN的语法:

UPDATE T1,T2
[INNER JOIN | LEFT JOIN] T1 ON T1.C1 = T2. C1
SET T1.C2 = T2.C2, 
    T2.C3 = expr
WHERE condition

查询:

$sql="UPDATE table_A 
INNER JOIN table_B ON table_A.name = table_B.name 
SET table_A.quantity = table_A.quantity - table_B.quantity
WHERE table_B.status = 'APPROVED'";