0

Please check the image.

two table, fevorite table and post table.

Here i have 2 table. One is post table and another is fevorite table. Both has primary key and post_id is FOREIGN_KEY in fevorite table.

Now my needs are:

  1. Select post_id list from fevorite table WHERE fevorite_by=2.
  2. Using this post_id list get post details (post_title,created_by, ...) from post table.

I need all of those things in single query. Thanks in advance.

1
  • please add a comment before giving a downvote. Commented May 23, 2016 at 18:12

1 Answer 1

1

Use sub query to get your result:

SELECT * FROM Post WHERE post_id IN ( SELECT post_id FROM fevorite WHERE fevorite_by = 2) 

Or you can do it by JOIN

SELECT P.* FROM Post P JOIN fevorite F ON F.post_id = P.post_id WHERE F.fevorite_by = 2 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.