首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > Mysql >

sql语句 查询解决方案

2012-02-27 
sql语句 查询SQL codeselect count(subid) as subnum,st.id,t.title,t.content from subtopics st JOIN to

sql语句 查询

SQL code
select 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

热点排行