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

求一条sql话语,多表关联,join

2012-09-21 
求一条sql语句,多表关联,joinusermessage(id,username,password,touxiang)用户信息表,表messagelist(id,ti

求一条sql语句,多表关联,join
usermessage(id,username,password,touxiang)用户信息表,表messagelist(id,title,username,time,content,class1,class2)发帖人信息表,表huifbiao(id,username,time,content,huifuid)回帖人信息表
上面三个表,如何写join语句,一条sql同时查询出回帖人个人信息和回帖人回帖的内容?

[解决办法]

SQL code
-->tryselect c.*,a.title,a.time,b.* from messagelist a,huifbiao b,usermessage cwhere a.id=b.id and a.username=c.username
[解决办法]
SQL code
select a.*,b.touxiangfrom huifbiao a inner join usermessage b on a.id=b.id and a.username=b.usernameleft join messagelist c on a.huifuid=c.idwhere c.id is not null
[解决办法]
探讨

引用:
SQL code

select a.*,b.touxiang
from huifbiao a inner join usermessage b on a.id=b.id and a.username=b.username
left join messagelist c on a.huifuid=c.id
where c.id is not null

……

[解决办法]
探讨

引用:
SQL code

select a.*,b.touxiang
from huifbiao a inner join usermessage b on a.id=b.id and a.username=b.username
left join messagelist c on a.huifuid=c.id
where c.id is not null

……

[解决办法]
SQL code
select a.*,b.touxiangfrom huifbiao a inner join usermessage b on a.id=b.id and a.username=b.usernameleft join (select id,title,username,min(time)timefrom messagelist group by id,title,username) c on a.huifuid=c.idwhere c.id is not null 

热点排行