php - 更新表a和表b

标签 php mysql join

TABLEA ( id - gcoins )
TABLEB ( id - prezzo )

我应该做一种减法:在“gcoins”的数量/值处减去“prezzo”的数量/值。

我尝试过:

UPDATE TABLEA SET TABLEA.gcoins = TABLEA.gcoins - TABLEB.prezzo FROM TABLEA JOIN TABLEB ON TABLEA.id = TABLEB.id;

我在 2010 年在该网站的问题中读到了相同的代码,但不起作用。

Error: 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 'FROM TABLEA JOIN TABLEB ON TABLEA.id = TABLEB.id' at line 1

最佳答案

尝试这个重写。

UPDATE  TABLEA JOIN TABLEB
            ON TABLEA.id = TABLEB.id
SET     TABLEA.gcoins = TABLEA.gcoins - TABLEB.prezzo

关于php - 更新表a和表b,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43081502/

相关文章:

php - 如何返回空的 json_encode 对象

MySQL exists 查询添加异常,SELECT 最大值+1

sql - 在 JOIN 之后选择 DISTINCT 值

php - 捕获包含 "."或 ":"但不以句点结尾的行

php - 如何降低 recaptcha 难度级别

php - 加密或隐藏 url 中发送的字符串

mysql - 绕过 MySQL 的 SET NAMES UTF8

php - MySql 查询错误 1054

mysql - 在mysql中将不同的行连接成一行

php - mysql中按慢查询排序