【问题标题】:MySQL delete from table where column is emptyMySQL从列为空的表中删除
【发布时间】:2018-05-12 01:07:41
【问题描述】:

我正在尝试从 table1 中删除插入的数据,其中 table2 (sname) 中的某个列为空。我正在尝试通过左外连接来实现这一点,但还不了解它的基本原理。

 table1 | anum  pnum 
         ===========
          001   001
          002   001
          003   002
          004   002


 table2 | anum  sname
         ============
          001   'cooking'
          001   'cleaning'
          002   'teaching'
          003   NULL

非常感谢任何提示。

【问题讨论】:

  • 你的意思是要删除table1中table2中没有匹配的anum的行吗?
  • 我想删除table2的sname为空值的table1的加载数据

标签: mysql


【解决方案1】:

要删除 table1 中 table2 中 sname 对应值为 null 的行,请使用以下查询:

DELETE table1
FROM table1
JOIN table2
  ON table2.anum = table1.anum
WHERE table2.sname IS NULL;

【讨论】:

    【解决方案2】:
    DELETE 
    FROM table1
    
    INNER JOIN table2 
      ON table1.anum = table2.anum
    
    WHERE table2.sname IS NULL;
    

    【讨论】:

      猜你喜欢
      • 2017-11-02
      • 2022-11-01
      • 1970-01-01
      • 2016-02-17
      • 2014-01-06
      • 2021-08-21
      • 1970-01-01
      • 2013-09-19
      • 1970-01-01
      相关资源
      最近更新 更多