I'll be the first one to admit my SQL skills are lacking. Now...
Let's say we've got a database table called Posts with three columns: Id, RootId, and DateTime.
What I'd like to do is get the last (by DateTime) 20 distinct RootId values.
Here's the caveat though: RootId may be NULL, in which case we should consider that record as distinct, and instead of NULL, Id should be returned.
What would the query be?