I have a MySQL database in which every user has an account, and each account can have multiple permissions.
My ultimate goal is to get the account username and comma delimited list of permission identifiers. I can do two ways:
SELECT a.username, GROUP_CONCAT(rp.permission_id) as permission_ids
FROM account AS a
JOIN role_permission AS rp
ON rp.role_id = a.role_id
WHERE a.id = 1902
... or...
SELECT username
FROM account
WHERE id = 1902;
SELECT permission_id
FROM account_permission
WHERE account_id = 1902
With a single request, I get my results exactly the way I want. With two queries, I have to create a comma-separated list in the application (PHP) using a second result set.
Are there any performance reasons for NOT choosing the first option? I have never used GROUP_CONCAT before, so I don’t know its consequences in terms of performance.