日期:2014-05-16  浏览次数:20771 次

sql语句 查询
SQL code

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语句怎么写  


------解决方案--------------------
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
------解决方案--------------------
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