从表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

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...