I have this query:
SELECT a.*, b.id AS host_id, COUNT(c.event_id) AS count_joins, COUNT(d.event_id) AS joined
FROM (`events` AS a)
INNER JOIN `users` AS b ON `b`.`id` = `a`.`host_id`
LEFT JOIN `joins` AS c ON `c`.`event_id` = `a`.`id`
LEFT JOIN `joins` AS d ON `d`.`event_id` = `a`.`id` AND d.user_id = 1
WHERE `a`.`date` > '1000-10-10 10:10:10'
GROUP BY `a`.`id`
ORDER BY `a`.`date` ASC
LIMIT 20
It gets all events, the author, the number of joins and check if the current user (id = 1) joined the event.
I'm having problem checking if the user joined the event, it's returning the number of joins, not 1 if the user joined or 0 if not.