mysql - 在数据库中的 Prestashop 中使用 Inner Join 更新 SQL

标签 mysql database sql-update prestashop prestashop-1.6

我尝试更新 Prestashop 表中的数量。我有一个 INNER JOIN 从表“ps_product_attribute”获取 upc

UPDATE ps_stock_available
SET ps_stock_available.quantity =  ps_stock_available.quantity - 1
INNER JOIN ps_product_attribute ON  ps_product_attribute.id_product_attribute = ps_stock_available.id_product_attribute
WHERE ps_product_attribute.ups = 01900000118;

但我总是遇到这个错误:

 #1064 - You have an error in your SQL syntax; check the manual that corresponds
to your MySQL server version for the right syntax to use near 'INNER
JOIN ps_product_attribute ON ps_product_attribute.id_product_attribute = p' at line 3

有人可以帮助我吗?我尝试过很多不同的事情。

编辑: 我尝试了不同的方法:

通过 SELECT,我可以从 ps_stock_available 获取 id_product_attribute。

SELECT id_product_attribute
FROM ps_product_attribute
WHERE upc in ("01900000118","01900000119");

是否可以对结果进行更新?

UPDATE  ps_stock_available
SET  quantity =  quantity-1
WHERE id_product_attribute in ("result1", "result2");

最佳答案

我找到了解决方案!

SELECT sa.id_product, sa.id_product_attribute, sa.quantity, pa.upc
FROM ps_stock_available AS sa
LEFT OUTER JOIN ps_product_attribute AS pa ON pa.id_product_attribute = sa.id_product_attribute
WHERE sa.id_product = 140;

关于mysql - 在数据库中的 Prestashop 中使用 Inner Join 更新 SQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28844982/

相关文章:

MySQL 性能 - CHAR(64) 与 VARCHAR(64)

Python SQL 更新查询 : string or integer address expected instead of instance instance

mysql - 简化 MySQL 中的更新/插入(upsert)处理

mysql - 在 Django 中执行批量 SQL 插入

php - 在 PHP 和 MySQL 中组织和管理数千个 PDF 文件

python - 将传感器数据保存到树莓派数据库

mysql - 在c中将文件流传输到mysql

java - 使用加密的 OrientDB 2.2 数据库创建 Java API Graph 连接

mysql - SQL 查询未找到任何内容,但返回 1 行且全部为空

mysql - 我可以在一个查询中更新/选择表吗?