mysql中的not like检索问题

mysql中的not like检索问题

问题描述:

A表:

idtagname

1很长很长的字符

2无关的字符

3非常长的字符

 

B表:

idnavname

1长的

2短的

 

我希望找出,A表中的数据没有(模糊)包含B表的:也就是红色那条记录

 

我第一时间想到这样写:

SELECT * from A a where a.tagname not like  (SELECT b.navname from B b)

 

 

但是会出错:Subquery returns more than 1 row

 

 

求各位指导.

 

select * from A a where not exists (SELECT 1 from B b where locate(b.navname,a.tagname) > 0)

应该是这个,不能直接用like的

select * from A a where exists (select 1 from B b where a.idtagname not like b.idnavname)

用like 好像不恰当。
理解,去找出a数据中不包含b的就行了。
select * from a a where not exists(select 1 from b b where find_in_set(a.idtagname,b.idtagname));