而且,照你的意思:
a表中的所有值为a的记录,都与b表值为a的记录相等,所以你自己相要的结果根本就不能叫两个表中a=b的结果.

解决方案 »

  1.   

    --好像是我理解错了,楼主是这个意思吧?
    --a表中的a列和b表的b列相同的数据
    select *
    from a 
    where exists(select 1 from b where b=a.a)--查a表中的a列和b表的b列不同的数据
    select *
    from a 
    where not exists(select 1 from b where b=a.a)
      

  2.   

    --测试--测试数据
    create table a(a varchar(10))
    insert a  select 'a'
    union all select 'a'
    union all select 'a'
    union all select 'a'
    union all select 'a'
    union all select 'as'
    union all select 'ab'
    union all select 'ac'
    union all select 'ad'
    union all select 'aa'create table b(b varchar(10))
    insert b  select 'a'
    union all select 'a'
    union all select 'ab'
    union all select 'ac'
    union all select 'ad'
    union all select 'ae'
    go--a表中的a列和b表的b列相同的数据
    select *
    from a 
    where exists(select 1 from b where b=a.a)--查a表中的a列和b表的b列不同的数据
    select *
    from a 
    where not exists(select 1 from b where b=a.a)
    go--删除测试
    drop table a,b/*--测试结果--a表中的a列和b表的b列相同的数据
    a          
    ---------- 
    a
    a
    a
    a
    a
    ab
    ac
    ad(所影响的行数为 8 行)
    --查a表中的a列和b表的b列不同的数据
    a          
    ---------- 
    as
    aa(所影响的行数为 2 行)
    --*/