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

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

2012-04-14 
一个sql子查询的问题~~~~场景如下:微博表:id|content|userid用户关系表id|userid|followid现在想获取用户

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

热点排行