请教主一表与另一表是一对多关系.如何只取另一表的任一条记录与主表关联?主表 a 
id为主键id  d1 d2 d3 .....
---------------
1   2   3  3
2   3   3  7
3   4   4  2另一表 b  
key为主键
id  name   key .....
----------------
1   abc    1
2   dec    2
1   ddd    3
2   33a    4
2   333    5如何通过sql 得到结果为
id   name
---------------
1    abc
2    dec
3    null

解决方案 »

  1.   

    select * from b where id in(select * from a)
      

  2.   

    谢谢luli327() .
    好像不行的
      

  3.   

    select a.id,a.name from a 
    left join (
          select id,name from b 
         inner join (select id,min(key)  as key from b group by id)  c
    on b.key=c.key and b.id=c.id
    ) b on a.id=b.id
      
    *****************************************************************************
    欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码) 最新版本:20070212http://www.cnblogs.com/feiyun0112/archive/2006/09/20/509783.html