sql语句 查询解决方案
sql语句 查询SQL codeselect count(subid) as subnum,st.id,t.title,t.content from subtopics st JOIN to
sql语句 查询
SQL codeselect count(subid) as subnum,st.id,t.title,t.content from subtopics st JOIN topics t ON st.id=t.idwhere 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