I am building a simple social network where I have the following schema( I did not include all the fields in the tables, just the ones that are relevant):
tbl_users:
id
username
tbl_friends:
user_id FK tbl_users.id
friend_id FK tbl_users.id
tbl_questions:
id
user_id
title
date_created
tbl_answers:
id
question_id
body
What I want is to retrieve all the questions belonging to a user's friends with each question having a limit of 3 answers. The result will have a limit to be efficient, lets say the last 5 added questions of my friends. I want a scalable solution if anyone can help with this. I managed to do this having 2 queries: 1st query finds all my friends SELECT id FROM tbl_friends WHERE user_id=:id OR friend_id=:id
After that I used the result for a WHERE IN clause to only get the questions. I could not get the answers, I made a SELECT for each answer. My solution is inefficient and not scalable and I want to find a better solution for my problem.
I also have to ask this...would noSQL be better in this situation?