有两个table
table1(aid,name)
table2(cid,aid,message)table1 data:
1,abc
2,def
3,xyztable2 data:
1,1,hello
2,1,hi
3,2,welcome我想在取出table 1的所有资料时,也可以知道有多少纪录在table2里SELECT Count(*) AS [count], table1.name
FROM table1 INNER JOIN table2 ON [table1].aid=[table2].aid group by table1.name;结果:
count,name
2,abc
1,def这句显示不到纪录3的资料,请问如何显示为:
2,abc
1,def
0,xyz谢谢

解决方案 »

  1.   

    select 
          [count] = (select count(1)
                     from table2 
                     where table2.aid = table1.aid),
           name
    from table1
      

  2.   

    select 
          [count] = (select count(1)
                     from table2 
                     where table2.aid = table1.aid),
           [name]
    from table1
      

  3.   

    不行啊You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '[count] = (select count(*)
    from complain
    where table2.aid = table1.aid' at line 2