SELECT `a`.`name` AS `author_name`, `b`.`name` AS `book_name`
FROM (
SELECT `author_id`, `name`,
ROW_NUMBER() OVER (PARTITION BY `author_id` ORDER BY `id` DESC) AS `row`
FROM `books`
) AS `b`
JOIN `authors` AS `a`
ON `b`.`row` < 6 AND `a`.`id` = `b`.`author_id`
WHERE `a`.`id` IN (список id)
ORDER BY `a`.`name`, `b`.`name`
SELECT `e`.`id`, `e`.`name` as `event_name`, `e`.`country_id`, `e`.`description`,
`c`.`name` as `country_name`, `l`.`links`, `i`.`images`
FROM `events` AS `e`
JOIN `countries` AS `c`
ON `c`.`id` = `e`.`country_id`
LEFT JOIN (
SELECT `event_id`, GROUP_CONCAT(`link`) AS `links`
FROM `links`
GROUP BY `event_id`
) AS `l`
ON `l`.`event_id` = `e`.`id`
LEFT JOIN (
SELECT `event_id`, GROUP_CONCAT(`name`) AS `images`
FROM `images`
GROUP BY `event_id`
) AS `i`
ON `i`.`event_id` = `e`.`id`
ORDER BY `e`.`id` DESC
LIMIT :start, :max
SELECT ANY_VALUE(user_dolg.user_id), ANY_VALUE(users.users_id), users.name,
ANY_VALUE(user_dolg.date), ANY_VALUE(user_dolg.dogovor_name), COUNT(*) AS cnt
FROM users
INNER JOIN user_dolg ON user_dolg.user_id = users.users_id
WHERE `date` BETWEEN '2019-02-01' AND '2019-02-28' AND komandi='командировка'
GROUP BY users.name;