关于sql查询,以显示关于新闻源的关注者数据 [英] Regarding sql query to show followers data on newsfeed

查看:89
本文介绍了关于sql查询,以显示关于新闻源的关注者数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在实施类似twitter.com的类似网站,我有两个表一个有推文信息,另一个有关注者信息,我想显示来自tweet表中的数据在tweet表userid = @ userid以及Followers表userid = FollowTOid。

例如:

在tweet表中用户id = 1并且在关注者表中我想知道userid 1s跟在列表中所以在关注表userid(1)= FollowToid。



bcoz在twitters新闻提要我们可以看到我们自己的推文以及以下推文



所以请告诉我如何在sql中为它编写查询。

I am implementing similar website like twitter.com and i have two table one having tweet information and one having followers information and i want to show data from tweet where in tweet table userid=@userid as well as in Followers table userid=FollowTOid.
for example:
in tweet table user id=1 and in followers table i want to know that userid 1s following list so in follow table userid(1)=FollowToid.

bcoz in twitters news feed we can see our own tweets as well as following tweet

so please tell me how i can write query for it in sql.

推荐答案

看起来你想要将这两个表一起加入如下



It looks like you want to join the two tables together like the following

select t.* from TweetTable t left join FollowerTable F on t.userid = f.followTOid where t.userid = @userid





有不同类型的连接和你的老朋友谷歌,会有很多关于这个主题的信息



There are different types of joins and your old friend google, will have lots of information on this subject


选择*来自Tweet,其中userid in(选择FollowToId from Follow where userid = @ userid)
Select * from Tweet where userid in (select FollowToId from Follow where userid =@userid)


这篇关于关于sql查询,以显示关于新闻源的关注者数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆