friend ,
我有一段代码需要从 ASP 迁移到 PHP。我在 MySQL 方面相当不错(或者我认为...),但在 SQL Server 方面不太好,而且之前的代码没有文档。
SQL查询:
UPDATE tab1 SET colx = '0'
FROM (SELECT tab1.id
FROM tab1 LEFT OUTER JOIN tab2
ON tab1.col1 = tab2.col1
AND tab2.col1 = tab1.col2
AND tab1.col3 = tab2.col4
WHERE tab2.col1 IS NULL
OR tab2.col4 IS NULL
) AS aux1
INNER JOIN tab1 ON aux1.id = tab1.id;
我不知道 MySQL 中的这个语法。欢迎任何提示。
错误信息:
1064 - You have an error in your SQL syntax; check the manual that correspond to your MySQL server version for the right syntax to use near 'AS aux1 INNER JOIN tab1 ON aux1.id = tab1.id'
最佳答案
你的查询逻辑有点乱,我已经提炼如下:
UPDATE tab1
LEFT JOIN tab2
ON tab2.col1 = tab1.col1
AND tab2.col1 = tab1.col2
AND tab2.col4 = tab1.col3
SET tab1.colx = '0'
WHERE tab2.col1 IS NULL
关于mysql - SQL Server 到 MySQL 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25016978/