Something like this might be what you want:
SELECT β¦ FROM atable WHERE zip = @zip UNION ALL SELECT β¦ FROM atable WHERE NOT EXISTS ( SELECT * FROM atable WHERE zip = @zip ) AND zip LIKE CONCAT(LEFT(@zip, 3), '%')
This may not be the most effective solution, but at least this is the only request that could be the starting point.
source share