I wrote this sql statement:
SELECT
e.id AS event_id, e.title, e.date, e.category, e.place, e.minAge, e.maxAge,
p.id, p.name, p.coor, p.nz,
a.user, a.event, COUNT(a.user) AS attending,
i.user_id, i.event_id
FROM events AS e
LEFT JOIN attendance a ON a.event = e.id
LEFT JOIN places p ON p.id = e.place
LEFT JOIN invited_friends i ON ( i.event_id = e.id ) AND ( i.user_id = 0 )
GROUP BY e.id
ORDER BY attending DESC
This statement selects events from table events and join some tables. everything is good so far.
I have another table called: invited_friends.
event_id bigint(20)
user_id int(11)
owner tinyint(1)
This table stores the user ids that invited to event.
The problem is that not every event is a private event, not every event got invited friends… the way I can tell if event is private or not is the column: category in event table, if it = 4 then it is a private event.
My inner join works, but it ignores all the public events because they have no invited friends.
How can I fix that?
Thanks in advance.
1 Answer