簡體   English   中英

MySQL從表為空的表中刪除

[英]MySQL delete from table where column is empty

我正在嘗試從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

任何提示都受到高度贊賞。

要刪除表1中表2中sname的對應值為空的行,請使用以下查詢:

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

INNER JOIN table2 
  ON table1.anum = table2.anum

WHERE table2.sname IS NULL;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM