微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

从表B中删除带有通配符的表a之类的列值

如何解决从表B中删除带有通配符的表a之类的列值

所以我有两个桌子

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删除domain中不包含seeds的行

您尝试了什么?

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。