简体   繁体   English

从表 B 中删除,其中列值类似于带有通配符的表 a

[英]Delete from table B where column value like table a with wildcards

So I have two tables所以我有两张桌子

seeds
- id
- domain

subdomain
- id 
- domain
- ip

I want to filter the subdomains against the domains我想根据域过滤子域

for example例如

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

I'm trying to write a single query that deletes the rows in subdomain that don't contain a domain from seeds我正在尝试编写一个查询来删除subdomain不包含来自seedsdomain的行

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

and

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)

both of these queries just delete all of the rows这两个查询都只是删除所有行

You can use not exists :您可以使用not exists

delete from subdomain
where not exists (
    select 1
    from seeds s
    where subdomain.domain like concat('%', s.domain)
)

DEMO演示

Use the LEFT JOIN + NULL pattern to find rows that don't match.使用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演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从表B中删除,其中表A中不存在值 - Delete from table B where value does not exists in Table A 从表中选择A列或B列中的值 - Select from table where value in column A or column B 从表中选择 [列 a],其中没有 [列 b = 任意值] 的实例 - Select [column a] from table where there are no instances of [column b = arbitrary value] 从表 B 更新表 A 中的列,其中值不存在于 MYSQL 中表 B 的不同结果中 - Update column in Table A from Table B where value does not exist in distinct result from Table B in MYSQL 从mysql表中删除行,其中值不喜欢 - Delete row from mysql table where value not like 在SQL中,从表a中选择全部,其中列a的值等于表b中最新条目的值? - In SQL, select all from table a where column a value equals the value of the most recent entry in table b? 从'table2'中删除,其中column ='value'如果'table1'='value'中的列 - Delete from 'table2' where column = 'value' IF column in 'table1' = 'value' mysql select * from table from table where column a value = column b value laravel - mysql select * from table where column a value = column b value laravel MySQL从表为空的表中删除 - MySQL delete from table where column is empty B列表2中的返回值,其中A列表1匹配A列表2 - Return Value in Column B Table 2, where column A Table 1, matches Column A Table 2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM