Find nearest values from MySQL Table
SELECT id, type, rate
FROM
( ( SELECT id, type, rate, 25-rate AS diff
    FROM rates
    WHERE type = 'A'
      AND rate &lt; 25
    ORDER BY rate DESC
      LIMIT 3
  ) 
  UNION ALL
  ( SELECT id, type, rate, rate-25 AS diff
    FROM rates
    WHERE type = 'A'
      AND rate &gt;= 25
    ORDER BY rate ASC
      LIMIT 3
  ) 
) AS tmp
ORDER BY diff
LIMIT 3 ;


Test at SQL-Fiddle