读书人

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

发布时间: 2012-04-14 17:14:21 作者: rapoo

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

读书人网 >Mysql

热点推荐