A) I need Data if Posted By My Friends
select f.userid,f.friendids,md.Name,post.Post,fc.Category
from post
left join friends f on friendids = post.userids
left join MasterData md on md.userid = f.friendids
left join FriendCategory fc on f.FriendCategory = f.FriendCategory
where f.userid = 1
B) I need Data if Posted By i am Subscribed to
select f.SubscribersID as userid,f.SubscribToID,md.Name,post.Post,fc.Category
from post
left join Subscribers f on SubscribToID = post.userids
left join MasterData md on md.userid = f.SubscribToID
left join FriendCategory fc on f.FriendCategory = f.FriendCategory
where f.SubscribersID = 1
c) If User is My Friend Subscribed as Well Then it Must Show Friend not i am Subscribed
select userid,friendids,name,post,case when sum(flag)=3 then 'I m subscribed to' else 'Friend' end as Category
from
(
select f.userid,f.friendids,md.Name,post.Post,fc.Category, 1 as flag
from post
left join friends f on friendids = post.userids
left join MasterData md on md.userid = f.friendids
left join FriendCategory fc on f.FriendCategory = f.FriendCategory
where f.userid = 1
select f.SubscribersID as userid,f.SubscribToID,md.Name,post.Post,fc.Category , 3 as flag
from post
left join Subscribers f on SubscribToID = post.userids
left join MasterData md on md.userid = f.SubscribToID
left join FriendCategory fc on f.FriendCategory = f.FriendCategory
where f.SubscribersID = 1
)
as a
group by userid,friendids,name,post
Happy Coding!
:)