1

I have spent hours and still couldn't able to do it correctly. I have user table, and posts table.

User table

username | followers        | following

john     | mary,steven,joel | anthony,matthew

Posts table

fromuser | post                    | date 

mary     | Bla bla, today is cold. | 1475982647

I need to get posts from the users who are being followed. Tried this;

SELECT * FROM posts WHERE $member[nick] 
IN (SELECT followers FROM users WHERE $member[nick] IN followers ORDER BY id DESC limit 10

This doesn't return any posts. What is the correct way to do it ?

Madhawa Priyashantha
  • 9,427
  • 7
  • 31
  • 59
caner taşdemir
  • 203
  • 3
  • 8

1 Answers1

1
SELECT *
FROM posts
WHERE FIND_IN_SET(fromuser,
                  (SELECT following FROM users WHERE username = 'john')) > 0

This query uses FIND_IN_SET to check each user appearing in posts whether or not he is being followed by a given user (John in this case).

Tim Biegeleisen
  • 451,927
  • 24
  • 239
  • 318