SELECT a.id AS nejblizsi_nizsi, b.id AS nejblizsi_vyssi FROM `tabulka` a JOIN `tabulka` b ON (a.id < $id AND b.id>$id) ORDER BY (b.id-a.id) ASC LIMIT 1