I'm no good at writing MySQL queries, so this query isn't working as it should. I want to select all "group"s, and fetch external information on the groups by IDs saved in group, like the group's creator, last person to update it and the number of images in the group.
In this query I'm using INNER JOIN, but apparently groups that have no images arent selected in this query. I want the query to select ALL groups no matter what, and fetch information on all the groups using the IDs. If a group has no images, i want the image count to be 0, not the group to be ignored.
This is the current query:
SELECT g.id, g.name, g.date_created, g.date_updated, g.created_by,
c.fullname AS creator_name, g.updated_by, u.fullname AS updater_name, COUNT(i.id) as image_count
FROM gallery_groups g INNER JOIN
users c INNER JOIN
users u INNER JOIN
gallery_images i
WHERE g.created_by=c.id AND g.updated_by=u.id AND i.group=g.id $id
GROUP BY g.name
ORDER BY g.date_updated DESC, g.name
I have tried replacing INNER JOIN with LEFT JOIN, RIGHT JOIN and OUTER JOIN, but all just result in sql errors.
Thanks for any and all help!