从 table B 中删除列值类似于 table a 的通配符

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 的行

What have you tried?

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)
)

DEMO

使用 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

DEMO