SELECT `r`.`ball`
FROM (
(SELECT `ball`, 0 AS `order`
FROM `ratings`
WHERE `type_id` = :priceItemsId
AND `type_name` = 'price_items')
UNION (SELECT `r`.`ball` AS `ball`, 1 AS `order`
FROM `price_items` AS `i`
JOIN `ratings` AS `r`
ON `i`.`id` = :priceItemsId
AND `r`.`type_id` = `i`.`price_id`
AND `r`.`type_name` = `price`)
) AS `r`
ORDER BY `r`.`order`
LIMIT 1
SELECT CONCAT(`h`.`hour`, ':', `m`.`minute`, ':00')
FROM (
SELECT '09' AS `hour`
UNION SELECT '10'
UNION SELECT '11'
UNION SELECT '12'
UNION SELECT '13'
UNION SELECT '14'
UNION SELECT '15'
UNION SELECT '16'
UNION SELECT '17'
) AS `h`
JOIN (
SELECT '00' AS `minute`
UNION SELECT '15'
UNION SELECT '30'
UNION SELECT '45'
) AS `m`