SELECT
	x.id AS id,
	MAX(x.name) AS name,
	MAX(x.hue) AS hue,
	MAX(x.access_public) AS access_public,
	MAX(x.access_level_default) AS access_level_default,
	GROUP_CONCAT(y1.level, ',') AS access_level_attributed_group,
	GROUP_CONCAT(y2.level, ',') AS access_level_attributed_user
FROM
	calendars AS x
	LEFT OUTER JOIN calendar_access_attributed_group AS y1 ON ((x.id = y1.calendar_id) AND (y1.group_id IN (SELECT group_id FROM user_groups WHERE (user_id = $user_id))))
	LEFT OUTER JOIN calendar_access_attributed_user AS y2 ON ((x.id = y2.calendar_id) AND (y2.user_id = $user_id))
GROUP BY
	x.id
;
