Given a table like:
object subject ID parentID
------ ------- ----- --------
A NULL 1 0
B NULL 2 0
C NULL 3 0
D NULL 4 0
E NULL 5 0
Null CC 6 1
Null DD 7 2
Null EE 8 2
I need a query with good performance that returns the following result:
result
------
A
CC
B
DD
EE
Best Answer
You can use coalesce, it's a function that returns its leftmost non-null argument:
Coalesce is a shorter form of: