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

一个sql子查询的问题~~~~
场景如下:

微博表:id | content | userid

用户关系表 id | userid | followid

 

现在想获取用户和自己的所有的微博信息, select content from weibo w where w.userid = (select followid from user_relation where userid = "1") 这样查询到的是好友的微博列表 怎么一次查询得到所有的信息? 子查询里面怎么加上自己的id呢?

------解决方案--------------------
探讨
场景如下:

微博表:id | content | userid

用户关系表 id | userid | followid



现在想获取用户和自己的所有的微博信息, select content from weibo w where w.userid = (select followid from user_relation……

------解决方案--------------------
select content from weibo w where w.userid = (select followid from user_relation where userid = "1")
union all
select content from weibo w where w.userid ="1"

------解决方案--------------------
探讨

select content from weibo w where w.userid = (select followid from user_relation where userid = "1")
union all
select content from weibo w where w.userid ="1"