Compare possible null values in one query
Your 2nd query seems correct and does what you want.

Another option would be to use the TOP .. WITH TIES but this works only because NULL values are treated as the lowest in SQL Server.

SELECT TOP (1) WITH TIES t.*
FROM cte AS t
ORDER BY t.NodeId DESC ;


If you had MIN() instead of MAX() and you tried the TIES with ASC instead of DESC, the above would fail miserably.