On 2016/04/05 10:47 AM, Domingo Alvarez Duarte wrote: > Hello ! > > I want to achieve this: > > select 1 as num > union > select 3 as num > union > select -2 as num > > order by abs(num) -- result [1, -2, 3] > > But it doesn't work this works but doesn't show what I want: > > select abs(num) > from ( > select 1 as num > union > select 3 as num > union > select -2 as num > ) > > order by abs(num) -- result [1,2,3] > > > > I know I can duplicate the column value but there is a way to do it without > duplicating ?
SELECT num FROM ( select 1 AS num union select 3 union select -2 ) ORDER BY abs(num) -- OR -- WITH t(num) AS ( select 1 union select 3 union select -2 ) SELECT num FROM t ORDER BY abs(num)