Самый простой вариант - использовать SUBSTRING_INDEX:
SELECT
`name`,
(SELECT
SUBSTRING_INDEX(
GROUP_CONCAT(`images`.`name` SEPARATOR ","),
",",
5
)
FROM `images`
WHERE `images`.`album_id`=`albums`.`album_id`
ORDER BY `images`.`image_id` DESC
)
FROM `albums`
ORDER BY `album_id` DESC
LIMIT 10
Можно вытаскивать необходимые данные по одному экземпляру
SELECT
`albums`.`name`,
CONCAT_WS(',',
(SELECT `images`.`name`
FROM `images`
WHERE `images`.`album_id`=albums.`album_id`
ORDER BY `images`.`image_id` DESC
LIMIT 0,1
),
(SELECT `images`.`name`
FROM `images`
WHERE `images`.`album_id`=albums.`album_id`
ORDER BY `images`.`image_id`
DESC LIMIT 1,1
),
(SELECT `images`.`name`
FROM `images`
WHERE `images`.`album_id`=albums.`album_id`
ORDER BY `images`.`image_id`
DESC LIMIT 2,1
),
(SELECT `images`.`name`
FROM `images`
WHERE `images`.`album_id`=albums.`album_id`
ORDER BY `images`.`image_id`
DESC LIMIT 3,1
),
(SELECT `images`.`name`
FROM `images`
WHERE `images`.`album_id`=albums.`album_id`
ORDER BY `images`.`image_id`
DESC LIMIT 4,1
)
) AS 'images'
FROM `albums`
ORDER BY `album_id` DESC
LIMIT 10
НЕ РАБОТАЕТ. Также можно группировать с объединением после получения необходимой выборки в подзапросе:
SELECT
`name`,
(SELECT
GROUP_CONCAT(innerquery.`name`)
FROM
(SELECT `images`.`name`
FROM `images`
WHERE `images`.`album_id`=`albums`.`album_id`
ORDER BY `images`.`image_id` DESC
LIMIT 5
) AS innerquery
)
FROM `albums`
ORDER BY `album_id` DESC
LIMIT 10