select * from tab where b in (select b from tab where a='0003')

解决方案 »

  1.   

    select * from tbname t where b=(select max(tt.b) from tbname tt where tt.a='0003');
      

  2.   

    写法很多啊
    select 
      a.a,a.b
    from 
      tab_name a,
      (select distinct b from tab_name where a='0003') b
    where 
      a.b=b.b;
      

  3.   

    这样的怎样
    select b.m1,b.m2
    from table a, table b
    where a.m2 = b.m2 and a.m1='003'
      

  4.   

    东子的办法不可行。
    按照东子的招,两个相似的表进行连接,a表的每条记录将与b表的每条记录进行连接,将会多出很多记录出来。以楼主的数据为例,前两条记录也满足a.m2 = b.m2 and a.m1='003'的条件。
      

  5.   

    楼主的字段A是主键吗?如果是就很简单,将一楼的in改为=就行了:
    select * from tab where b =(select b from tab where a='0003');
      

  6.   

    to biliky() 
    你的方法是不对的.换成=号以后,如果select b from tab where a='0003'多行就报错了.所以就in是正确的.
      

  7.   

    to  liuyi8903(西西)你没看到我说前提吗?我是在保证字段A为主键的基础上吗?A为主键与a='0003'对应的b肯定只有一个值啊。