I have a PHP/MySQL scenario where I want to display a list of events but also show all users assigned to an event. In MySQL I have an events
, eventusers
and users
tables.
I can SELECT event_id, event_name FROM events
then loop through results in PHP and then SELECT user_id FROM eventusers WHERE event=[event_id]
in each result loop to get that particular event's users.
I am wondering if there is way to do this in one single SQL query (and it's also performance decent) so I get data from the events
table as well as all the user IDs attached to the event from the eventusers
table. Something like:
event id | event name | Users from eventusers table
------------------------------------------
1 | Soccer match | 3,56,79
2 | Cycling | 46,77,88,126,78