一个sql子查询的有关问题~

一个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″

一个sql子查询的有关问题~

相关文章:

你感兴趣的文章:

标签云: