SELECT * FROM usm_users
LEFT JOIN (
	SELECT uar_user_id,
	GROUP_CONCAT(role_name ORDER BY uar_role_id) AS role_names_concat,
	GROUP_CONCAT(uar_role_id ORDER BY uar_role_id) AS role_ids_concat,
	GROUP_CONCAT(COALESCE(role_color,'') ORDER BY uar_role_id) AS role_colors_concat
	FROM usm_users_at_roles
	JOIN usm_roles ON uar_role_id = role_id
	# LEFT JOIN (
	# ) groups ON 
	GROUP BY uar_user_id
) roles ON uar_user_id = user_id
WHERE CASE
	WHEN :ids IS NOT NULL THEN user_id IN (:ids)
	WHEN :sessionkey IS NOT NULL THEN user_session_key = :sessionkey
	WHEN :activation IS NOT NULL THEN user_activation_key = :activation
	WHEN :username IS NOT NULL AND :password IS NULL THEN user_name = :username OR user_email = :username
	WHEN :username IS NOT NULL AND :password IS NOT NULL THEN 
		( user_name = :username OR user_email = :username) AND
		user_password_hash = :password
	ELSE user_id != 1 #all users
END