Toto je jedna cesta k tomu pomocí self-join a union
.
select t1.val
from t t1
join t t2 on t1.val = t2.val-1
union
select t2.val
from t t1
join t t2 on t1.val = t2.val-1
order by 1
Edit:Uvědomil jsem si, že to lze provést jediným dotazem namísto použití union
.
select distinct t1.val
from t t1
join t t2 on t1.val = t2.val-1 or t1.val = t2.val+1
order by 1