简体   繁体   English

使用INNER JOIN进行UPDATE的查询语法错误

[英]Query Syntax Error for UPDATE with INNER JOIN

Hey i have an update query with an inner join but i cannot get the syntax correct to make it work... this is what i currently have: 嘿,我有一个内部连接的更新查询,但我无法使语法正确,使其工作...这是我目前有:

UPDATE t1 
   SET t1.quantity = t1.quantity - ?  FROM items t1
INNER JOIN users t2 ON t1.id=t2.id
   WHERE t1.item_id=? AND t2.uid= ?

The syntax error says its near here: 语法错误说它在附近:

near 'FROM items t1 INNER JOIN users t2 ON t1.id=

I'm using pdo encase you wondered why i have question marks! 我正在使用pdo包装你想知道为什么我有问号!

Hope you can help! 希望你能帮忙!

Try following query, the syntax you have is valid in SQL Server but not in MySQL 尝试以下查询,您的语法在SQL Server中有效,但在MySQL中无效

UPDATE items t1
INNER JOIN users t2 ON t1.id=t2.id
SET t1.quantity = t1.quantity - ?  
WHERE t1.item_id=? AND t2.uid= ?

SQL DEMO SQL DEMO

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM