'Select rows that have a value matching any one of multiple rows from a second table
Still a mySQL beginner. I have two tables, follows
and events
, that have these columns:
FOLLOWS
user | profile
EVENTS
user | profile | other_stuff
I want to get a list of relevant events from events
based who the user is following.
SELECT * FROM follows WHERE user = $userId
retrieves the people that the user is following.
Now how can I select all the rows in events
where profile
matches the value of profile
from any of the people that the user is following?
Solution 1:[1]
Like this:
select *
from follows f
join events e on e.user = f.user
where f.user = $userId
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Metaphor |