SELECT *
FROM `table`
WHERE `field` = :value
UNION (
SELECT *
FROM `table`
WHERE `field` > :value
ORDER BY `field` DESC
LIMIT 1)
UNION (
SELECT *
FROM `table`
WHERE `field` < :value
ORDER BY `field`
LIMIT 1)
SELECT *
FROM `films` AS `f`
JOIN `filmsjanrs` AS `fj1` ON `fj1`.`filmid` = `f`.`id`
AND `fj1`.`janrid` IN (SELECT `id` FROM `janr` WHERE `name` = 'Ужасы')
LEFT JOIN `filmsjanrs` AS `fj2` ON `fj2`.`filmid` = `f`.`id`
AND `fj2`.`janrid` IN (SELECT `id` FROM `janr` WHERE `name` = 'Комедия')
WHERE `fj2`.`filmid` IS NULL