SELECT *,
GROUP_CONCAT(group_function_ids) AS function_ids_concat,
GROUP_CONCAT(group_function_names) AS function_names_concat,
CONCAT(GROUP_CONCAT(group_id),',0') AS group_ids_concat,
GROUP_CONCAT(group_name) AS group_names_concat
FROM ( SELECT
	*,
	GROUP_CONCAT(function_id) AS group_function_ids,
	GROUP_CONCAT(function_name) AS group_function_names,
	GROUP_CONCAT(function_type) AS group_function_types
	FROM ( SELECT
		*
		FROM usm_users
		LEFT JOIN usm_user_in_group ON uig_user_id = user_id
		LEFT JOIN usm_groups ON uig_group_id = group_id
		LEFT JOIN usm_function_in_group ON fig_group_id = group_id
		LEFT JOIN usm_functions ON function_id = fig_function_id
		WHERE
			user_id = :user_id OR (	
				user_session_key = :auth AND
				LENGTH(user_session_key) >= 32 
			) OR (
				user_password_hash = :auth AND (
					user_name = :name OR
					user_email = :name
				)
			)
		) sub_user

	GROUP BY group_id, user_id
) sub_groups
GROUP BY user_id