BEGIN
SET @sql = NULL; SELECT GROUP_CONCAT(DISTINCT CONCAT( ‘MAX(IF(c.role_id = ‘’’, c.role_id, ‘’’, true, false)) AS ‘’’, role_name, ‘’’’ ) ) INTO @sql FROM tbl_role c;
SET @sql = CONCAT('Select staff.user_name, ‘, @sql, ’ From tbl_staff staff Left Join tbl_staffRole staffRole On staff.user_name = staffRole.user_name Left Join tbl_role c On c.role_id = staffRole.role_id Group by staff.user_name’);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END