Hi there,
I have several tables: programs, accommodations, events, and products. I'm trying to pull all of the columns out of the programs table, but also get a count to see how many accommodations, events and products each program has. I came up with this, but it's not working quite right. If anyone has any insight, it would be greatly appreciated.
SELECT p.*, COUNT(a.accommodation) AS accommodation_count, COUNT(e.event) AS event_count, COUNT(t.product) AS product_count
FROM programs as p
LEFT JOIN accommodations AS a ON (p.program = a.program)
LEFT JOIN events AS e ON (p.program = e.program)
LEFT JOIN products AS t ON (p.program = t.program)
WHERE p.program = '$program' GROUP BY p.program