[英]Delete from table B where column value like table a with wildcards
所以我有兩張桌子
seeds
- id
- domain
subdomain
- id
- domain
- ip
我想根據域過濾子域
例如
seeds
Id Domain
0 google.com
1 test.com
subdomain
Id domain ip
0 test.google.com null
1 api.google.com null
2 dnr.com null
3 neverssl.com null
我正在嘗試編寫一個查詢來刪除subdomain
不包含來自seeds
的domain
的行
你嘗試過什么?
delete subdomain
where id not in
(select subs.id from seed as seeds
join
subdomain as subs on subs.domain
like concat('%', seeds.domain));
和
delete subdomain
where id not in
(SELECT sd.id
FROM subdomain sd
LEFT JOIN seed s
ON sd.domain LIKE CONCAT('%', s.Domain)
WHERE s.id IS NULL)
這兩個查詢都只是刪除所有行
您可以使用not exists
:
delete from subdomain
where not exists (
select 1
from seeds s
where subdomain.domain like concat('%', s.domain)
)
使用LEFT JOIN
+ NULL
模式查找不匹配的行。
DELETE d
FROM subdomain AS d
LEFT JOIN seeds AS s ON d.domain LIKE CONCAT('%', s.domain)
WHERE s.id IS NULL
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.