• With Query1 As

    ( Select * from (values (1, 2), (4, 5), (2, Null), (2, 7), (1, 8)) As T(x,y))

    select MAX(x) Greatest, Min(x) Least From Query1

    Union All

    Select Max(y), MIN(y) From Query1