select max(version)
from my_table
where version != 'DEBUG'
union
select max(version)
from my_table
where not exists (select * from my_table where version != 'DEBUG');
Или, если вы используете mysql:
select ifnull(max(version), 'DEBUG')
from my_table
where version != 'DEBUG'
и для postgres:
select coalesce(max(version), 'DEBUG')
from my_table
where version != 'DEBUG'