Reputation: 474
I have two database table 'friends' and 'published_post'
`friends` --- contains 650K rows
--------------------------------------------------------
| fb_id_user(bigint) | fb_id_friend(bigint) | fb_username(text) |
---------------------------------------------------------
`published_post` ----- contains 6K rows
-------------------------------------------------------------------------------
| id(primary_key)(int) | fb_id(bigint) | post(text) | post_date(DATE_TIME) |
-------------------------------------------------------------------------------
suppose a user has facebook id '12345'. I want to get all the post(form published_post table
) given by his friends(from friends table where fb_id_user = '12345'
) in descending order of 'post_time'.
Any suggestion how this query can be done efficiently would be very helpful.
Upvotes: 0
Views: 60
Reputation: 19882
SELECT
pp.*
FROM published_post pp
LEFT JOIN friends f ON f.fb_id_user = pp.fb_id
WHERE pp.fb_id_friend = '12345'
ORDER BY f.post_date DESC
Upvotes: 3