我目前在这里有这个查询:
select * from outerb where not exists(
Select * from wms
where wms.barcode = outerb.barcode)
and (pcode = '' or pcode is null)
and (brand = '' or brand is null);
上面的查询给出了以下结果:
- 2 个表已针对同一列进行连接,在本例中为
条形码
。但使用了where not isn't
,因此它显示了两个表之间不存在的值。 - 还添加了另一条语句
and(pcode = '' 或 pcode 为空)
and (brand = '' 或brand 为空);
它显示指定单元格的空单元格。
最后,我需要根据上面的查询从 outerb
中删除所有这些值。
这是我迄今为止尝试过的:
Delete from outerb where(
select * from outerb where not exists(
Select * from wms
where wms.barcode = outerb.barcode) and (pcode = '' or pcode is null)
and (brand = '' or brand is null));
但收到错误消息Operand should contains 1 columns
最佳答案
你不需要外部闭包,直接使用exists子句即可:
DELETE
FROM outerb t1
WHERE NOT EXISTS (SELECT 1 FROM wms t2
WHERE t2.barcode = t1.barcode AND
(t2.pcode = '' OR t2.pcode IS NULL) AND
(t2.brand = '' OR t2.brand IS NULL));
关于mysql - 将 `delete from TABLE where (......)` 与括号内的多个查询一起使用 - MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56115107/