0

i have these tables in database

Users table

UserId | Username | password

Users Posts Table

PostId | PostsTitle | PostUser (The id of the User who post this )

Following Table

FollowId | Following | Follower

Now what is the best way to get the people i follow posts order by id in desc way

like twitter do

i came up with this MySql code i don't know if it's the best way to do this or there is another way to

SELECT * FROM posts 
WHERE PostUser in (
    SELECT follower 
    from Following 
    where Following=$loggedin_user);

i found this answer in here (Here)

Community
  • 1
  • 1

1 Answers1

4

Here is another way to do it, which I would recommend and instead of using IN()

SELECT
      Posts.PostId
    , Posts.PostsTitle
    , Posts.PostUser
FROM Posts
      INNER JOIN Following
                  ON Posts.PostUser = Following.Follower
WHERE Following.Following = $loggedin_user
;
Paul Maxwell
  • 33,002
  • 3
  • 32
  • 51