mysql - 将 `delete from TABLE where (......)` 与括号内的多个查询一起使用 - MySQL

标签 mysql

我目前在这里有这个查询:

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/

相关文章:

php - PDO异常 SQLSTATE[23000] :in php

php - App\Http\Controllers\缺少参数 1

java - 使用 JDBC 连接 JAVA 和 MySql

php - 将行值分配给按钮

mysql - SQL:如何查找包含特定分钟数的日期时间?

php - 使用 PHP 从数据库中检索数据

php - PDO SELECT WHERE 不起作用

java - 如何从MySql表列中检索特定字段的总和到变量中

php - 使用 php 跟踪文件下载进度

php - 在 MySQL 查询变量后添加 ORDER BY