select count(subid) as subnum,st.id,t.title,t.content from subtopics st JOIN topics t ON   st.id=t.id
where st.id in (select id from topics where viewid='1')
group by st.id我的链接条件 为t.id=st.id   但t.id对应的st.id有可能没没有  但我想显示t 表 的内容  SQL语句怎么写  

解决方案 »

  1.   

    select count(subid) as subnum,st.id,t.title,t.content from subtopics st right JOIN topics t ON   st.id=t.id
    where st.id in (select id from topics where viewid='1')
    group by st.id
      

  2.   

    JOIN 换成RIGHT JOIN 就可以了。select count(subid) as subnum,st.id,t.title,t.content from subtopics st RIGHT JOIN topics t ON   st.id=t.id
    where st.id in (select id from topics where viewid='1')
    group by st.id
      

  3.   

    select count(subid) as subnum,t.*  from subtopics st right outer JOIN topics t ON t.id=st.id
    where t.id in (select id from topics where viewid='1')
    group by t.id
    order by date desc我也试出来了  还是谢谢大家 O(∩_∩)O~