select * from 主表 a
where exists(select 1 from 从表 where BiaoHao = a.BiaoHao 
and shuliang1 = shuliang2)

解决方案 »

  1.   

    create table t1(a varchar(10),b varchar(10))
    create table t2(a varchar(10),c int,d int)insert t1
    select '100','200'
    union all select '200','2000'insert t2
    select '100',1,1
    union all select '100',1,2
    union all select '200',2,2
    union all select '200',3,3select * from t1 where a in(
    select a from t2 where c<>d)
      

  2.   

    --测试
    create table t1(a varchar(10),b varchar(10))
    create table t2(a varchar(10),c int,d int)insert t1
    select '100','200'
    union all select '200','2000'insert t2
    select '100',1,1
    union all select '100',1,2
    union all select '200',2,2
    union all select '200',3,3select * from t1 where a in(
    select a from t2 where c<>d)drop table t1
    drop table t2/*
    a     b
    ---------
    100   200
    */
      

  3.   

    select a.*
    from 主表 a join 从表 b on a.BianHao=b.BianHao
    where b.shuliang1<>b.shuliang2
      

  4.   

    to: zjcxc(邹建) 
    这样会查询出重复值其实我只是想找一种效率最高的查询方法,或解决方案
    因为数据多
    在shuliang1,shuliang2上没有索引!
      

  5.   

    不知道在select a.*
    from 主表 a join 从表 b on a.BianHao=b.BianHao
    where b.shuliang1<>b.shuliang2
    里面的select a.*改成
    select distinct a.*
    from 主表 a join 从表 b on a.BianHao=b.BianHao
    where b.shuliang1<>b.shuliang2
    行不行啊???