0

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.

1
  • 1
    The code uses backquotes so I removed the SQL Server tag. Commented Dec 30, 2013 at 12:31

1 Answer 1

3
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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.