SELECT DISTINCT
FIRST_VALUE(column_1) OVER (ORDER BY column_1 IS NULL, id DESC) column_1,
FIRST_VALUE(column_2) OVER (ORDER BY column_2 IS NULL, id DESC) column_2
FROM test;
SELECT DISTINCT
FIRST_VALUE(column_1) OVER (ORDER BY column_1 = ' ', id DESC) column_1,
FIRST_VALUE(column_2) OVER (ORDER BY column_2 = ' ', id DESC) column_2
FROM test;