I have this MySQL query
SELECT perms.permission_id, perms.long_title, perms.category, gperms.value FROM
acl_permissions AS perms JOIN acl_group_permissions AS gperms ON
(perms.permission_id = gperms.permission_id AND gperms.group_id = 1) WHERE
perms.type IN ('adm', 'cs') AND perms.simple_title NOT IN ('adm_', 'cs_')
ORDER BY perms.long_title
Basically the bit causing problems is in the ON. I want the query to return all rows from perms based on the where criteria regardless of whether there is a row matching gperms.group_id = 1.
gperms.value would ideally just be an empty string if there was no row matching gperms.group_id = 1.
You want to
LEFT OUTER JOIN(orLEFT JOINfor short) gperms instead of just a straight joinwhich will return
NULLfor gperms.value for any row that doesn’t join the gperms on the given condition.If you want an empty string instead of the
NULLyou can useIFNULL():