Sorry, that’s not a very clear title. Here’s what I’ve got:
SELECT u.name
FROM users u
INNER JOIN users_permissions
ON users_permissions.user_id = u.id
AND users_permissions.permission_id IN ( 1,2 )
LEFT JOIN users_events
ON users_events.user_id = u.id
AND users_events.event_id = 3
Ok, so:
Permission “1” lets you edit all events.
Permission “2” only lets you edit certain events, and those events are specified in table users_events.
I want the query result to include only those users who can edit the specified event.
In pseudo-logic, that’s:
where (permission = 1) or (permission = 2 and event = 3)
The query above will include a user with permission “2” (event-specific) even when the list of events they can edit doesn’t include the event I’m checking against.
In essence, I only care about JOINing the users table to the users_events table if the matched permission in the users_permissions table is “2”.
How do I do that? 🙂
You need to use the
WHEREclause: