SELECT MAX(b.a) from ( select distinct * from (values (1), (1), (1), (2), (5), (1), (6)) as Y(a) ) as b SELECT MAX(b.b) from ( select distinct * from (values (1,2), (1,3), (1,4), (2,5), (5,6), (1,7), (6,8)) as Y(a,b) ) as b SELECT MAX(b.c) from ( sel