Skip to content
Advertisement

Sql select from a table but use another table value as where clause [closed]

How can I select * from table posts but using table network_follow.follower as where condition?

I have table posts, column by_user

and table network_follow column follower

I don’t know if that’s the case, can somebody help?

select * from posts where posts.by_user = network_follow.follower = user_logged

Advertisement

Answer

Join the tables and then filter the network_follow table with the WHERE condition.

SELECT p.*
FROM posts AS p
JOIN network_follow AS n ON p.by_user = n.followed
WHERE n.follower = user_logged
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement