I have searched in a few topics for how to resolve this issue I am having with a query that uses CONCAT but yet must return the groups even if the concat is null and I have found 2 solutions that doesnt work.
First solution was to use ISNULL:
#1582 - Incorrect parameter count in the call to native function 'ISNULL'
Second was to use IFNULL which works partially, it does find which are not null but yet doesnt print the null ones.
Here is the query:
SELECT g.name, IFNULL(GROUP_CONCAT(c.name),'') AS commands
FROM site_access b
JOIN groups g ON b.group_id = g.id
JOIN group_commands gc ON g.id = gc.group_id
JOIN commands c ON gc.command_id = c.id
WHERE b.site_id = 1
GROUP BY g.name
ORDER BY g.status ASC
I have 8 site_access, 8 groups and currently registered and only 2 commands that are assigned to group 1 and group 2, what currently happens is that it does print these 2 groups but ignore all the rest because they dont have commands.
Here is an example of the output:
Admin - add, del, announce
Member - find
Desired output:
Admin - add, del, announce
Member - find
Banned
OhterGroup1
OhterGroup2
OhterGroup3
OhterGroup4
OhterGroup5
if you need more information about the tables there is a sample of it in here: MySQL query for multiple tables being secondary tables multiple items?