现在有两个表,表A存放的是字符串 12345.com.cn,表B存放的字符串类似com.cn,.gov.cn等现在要查询表A中的字符串不包含表B中字符串字段的行,也就是在表A的查询中排除表B中包含的字符串。求高手指点该SQL语句。

解决方案 »

  1.   

    --SQL2005
    select * from A
    excetp
    select * from B
      

  2.   


    select * from A where not exists(select 1 from B where charindex(B.col,A.col)>0)
      

  3.   

    select * from a ,b where charindex(cola,colb)<0
      

  4.   

    --SQL2005
    select * from A
    except
    select * from B
      

  5.   

    select ta.* from ta,tb where ta.colname not like '%'+tb.colname+'%'
      

  6.   

    select 
      * 
    from 
      A 
    where 
      not exists(select 1 from B where charindex(B.col,A.col)>0)
      

  7.   

    俺SQL盲,回帖真快,我先试验一下,对了过了在给分,多谢各位,嘿嘿~~
      

  8.   

    SELECT * FROM TB T 
    WHERE NOT EXISTS(SELECT 1 FROM TB1 WHERE T.COL LIKE '%'+B1.COL+'%')
      

  9.   

    select * from tb1 where not exists(select 1 from tb2 where charindex(tb1.col,tb2.col)>0)
      

  10.   

    --> 测试数据:@a 现在要查询表A中的字符串不包含表B中字符串字段的行
    declare @a table([cola] varchar(20))
    insert @a
    select '12345.com.cn' union all
    select 'fdsafds'
    --> 测试数据:@b
    declare @b table([colb] varchar(20))
    insert @b
    select 'com.cn' union all
    select 'gov.cn' 
    select distinct a.* From @a a ,@b  b where not exists(select 1 from @b where charindex(colb,a.cola)>0 )/*
    cola
    --------------------
    fdsafds
    */
      

  11.   

    结贴了,CSDN果然效率高,表A是我收集的域名数据库,表B是我要排除的域名比如是政府部门,我要再表A中找出正好是政府部门的站点。2楼的成功了。谢谢大家。后面的8,9,10就没看了,不好意思哈。分数给先发的啦~~
      

  12.   

    select * from  a where not exists (select 1 from B where a.字符串字段 like '%'+字符串字段'%')