从2个表查询数据select id,name,title  form tab1  where flag='0'select count(*)as mycount from tab2 where id= 上面从tabl查询出来的id需要同时取出id,name,title 和mycount 值这个关联SQL怎么写??这样写好象不行:select a.id,a.name,a.title,count(*) as mycount from tab1 a,tab2 b where a.id=b.id and a.flag='0'

解决方案 »

  1.   

    select a.id,a.name,a.title,b.mycount  form tab1 a 
    inner join
    (
    select count(*) as mycount from tab2 group by id
    )
    on a.id=b.id
    where a.flag='0'
      
    *****************************************************************************
    欢迎使用CSDN论坛阅读器 : CSDN Reader(附全部源代码) 
    http://www.cnblogs.com/feiyun0112/archive/2006/09/20/509783.html
      

  2.   

    select max(a.id),max(a.name),max(a.title),count(*) as mycount from tab1 a,tab2 b where a.id=b.id and a.flag='0'