I have a two tables, one which contains details of events (name,time,etc), and one which contains records of bookings customers have made for each of these events. I want to be able to query the database and get a set of results that contains all the fields in the events table, plus the number of bookings that there have been for each of these events, so something like:
event_name, event_time, total_spaces_available, number_of_bookings
At the moment I'm getting around this by looping through the results in PHP but is it possible to do within SQL?
I want to be able to do something like:
SELECT *, COUNT(SELECT * FROM bookings WHERE event_id=<VARIABLE>) FROM events But i don't know the syntax
I'm in MySQL
Any help would be much appreciated!