Reputation: 315
I have two tables names are feed, and friendship....
friendship table has these fields..toid which the session user id, fromid which is the friend id, and status that may be 0 or 1, and the feed table contains id,post_user_id which is the feed poster id, and contents. Now i want to get the feed from the feed table only from my friends i am able to get feeds from my friends but i can't get my own feed , when i put my own id in the condition the query is executed but the result empty. i tried these
SELECT * FROM feed WHERE `post_user_id` IN (Select fromid from
gr_user_friendships where toid = 47) ORDER BY
post_date_time DESC
/****This query giving only the friends records not mine to get my records also i put my own id in the condition agains****/
SELECT * FROM feed WHERE `post_user_id` IN (Select fromid from
gr_user_friendships where toid = 47) and `post_user_id` = 47 ORDER
BY post_date_time DESC
/*This time this results empty**/
I also tried this with inner join no success at all
Upvotes: 0
Views: 88
Reputation: 813
Try:
SELECT * FROM feed WHERE post_user_id = 47 or 'post_user_id' IN
(Select fromid from gr_user_friendships where toid = 47) ORDER BY
post_date_time DESC
Upvotes: 1
Reputation: 988
In your second query:
SELECT * FROM feed WHERE `post_user_id` IN (Select fromid from
gr_user_friendships where toid = 47) and `post_user_id` = 47 ORDER
BY post_date_time DESC
just replace and
with or
Upvotes: 1
Reputation: 380
Shouldn`t it work with an OR instead of the AND?
SELECT * FROM feed WHERE `post_user_id` IN (Select fromid from
gr_user_friendships where toid = 47) OR `post_user_id` = 47 ORDER
BY post_date_time DESC
Upvotes: 3
Reputation: 473
Try this..
SELECT * FROM feed INNER JOIN (Select fromid from
gr_user_friendships where toid = 47) WHERE 'toid' = 47 and `post_user_id` = 47 ORDER
BY post_date_time DESC
Upvotes: 0