I am new to web programming and I'm trying to make a twitter-clone. At this point, I have 3 tables:
users (id, name)
- id is the auto-generated id
- name of the user
tweets (id, content, user_id)
- id is the auto-generated id
- content is the text of the tweet
- user_id is the id of the user that made the post
followers (id, user_id, following_id)
- id is the auto-generated id
- user_id is the user who is doing the following
- following_id is the user that is being followed
So, being new to sql as well, I am trying to build an SQL statement that would return the tweets that the currently-logged in user and of everyone he follows.
I tried to use this statement, which works sometimes, but other times, I get an error that says "Subquery returns more than 1 row". Here is the statement:
SELECT * FROM tweets
WHERE user_id IN
((SELECT following_id FROM followers
WHERE user_id = 1),1) ORDER BY date DESC
- I put 1 as an example here, which would be the id of the currently logged-in user.
I haven't had any luck with this statement; any help would be greatly appreciated! Thank you.