现在我有两张表,内容如下:表A (正文)
ID Contents
1 aabbcc
2 abc
3 acd
4 abb表B (关键字表)
ID Keyword
1 ab
2 ac
3 aa
4 ko现在需要把正文表中含有表B关键字的记录去除,请问在Mysql中通过SQL、存储过程或者函数可以实现吗(比如有没有delete from A where Contents in (select Keyword from B) 这样的语句)?请解答的详细点,谢谢!

解决方案 »

  1.   

    表B的内容是整个(比如AB、AC),还是单一字母(比如A、B、CK、O),贴
    要求结果出来看看
      

  2.   

    按照上面的要求来说,结果果就是空表
    因为
    1 aabbcc 
    ab
    ac
    abb 都满足被过滤的要求。谢谢
      

  3.   

    如果是前者:
    select * from ba inner join bb on instr(ba.Contents,bb.Keyword)>0
      

  4.   

    select ba.* from ba left join bb on instr(ba.Contents,bb.Keyword)>0
    where bb.id is null
      

  5.   


    select *
    from a
    where not exists (select * from b where a.Contents like concat('%',Keyword,'%'));
      

  6.   

    或者select a.*
    from a left join b on INSTR(a.Contents,b.Keyword)>0
    where b.id is null