SELECT * FROM cms_medias
LEFT JOIN cms_nodes ON 
    ( media_node_id = node_id ) OR
    ( ISNULL(media_node_id) AND node_id = 1 AND media_id = 1) 
LEFT JOIN (
		SELECT
			media_crop_media_id,
			GROUP_CONCAT(media_crop_id) AS crop_ids_concat,
			GROUP_CONCAT(media_crop_format) AS crop_formats_concat,
			GROUP_CONCAT(media_crop_left) AS crop_left_concat,
			GROUP_CONCAT(media_crop_top) AS crop_top_concat,
			GROUP_CONCAT(media_crop_width) AS crop_width_concat,
			GROUP_CONCAT(media_crop_height) AS crop_height_concat,
			GROUP_CONCAT(media_crop_auto) AS crop_auto_concat
		FROM cms_media_crops
		GROUP BY media_crop_media_id
	) media_crops 
	ON media_crops.media_crop_media_id = media_id
WHERE ( 
	node_id = :node_id OR ISNULL(:node_id)
) AND (
	node_parent_node_id = :parent_node_id OR ISNULL(:parent_node_id)
) AND (
	!node_is_trashed OR :showtrashed
)
ORDER BY node_ordering

-- :preview
-- :showtrashed
-- :ids