I have three tables in my database: reservations, events and users. I want to display all the users that subscribed to a certain event. The tables are linked via the following method:
SELECT users.u_name, events.e_id, events.e_title
FROM users
INNER JOIN reservations
ON reservations.r_s_id = users.u_id
INNER JOIN events
ON reservations.r_event_id = events.e_id
I need to join the reservation table because the field reservations.r_s_id correlates with the unique id of the user (users.u_id) and then the field reservations.r_event_id correlates with the unique id of the events (events.e_id). This was the only method i could come up with to approach all the necessary values.
It is my goal to get an output like below but have no clue how to achieve this
Event 1 - user 1 - user 3 - user 9 Event 2 - User 2 - User 5 - User 12
I tried using GROUP_CONCAT() and GROUP BY on events.e_title but that did not resulted the way i want it to
Anybody an idea?
Select from reservations, order the result set by
events.e_idand print a new heading each time the event changes.Like this: