Reputation: 23
Here's is my main table. where i have three column with there dates. some of them are NULL values. i want to have outputt some thing like given below. i tried alot but couldnt get the correct answer. if someone can help. thanks.
a.id a.date b.id b.date c.id c.date
3 7/1/2014 11 NULL 21 NULL
5 8/1/2014 12 NULL 22 NULL
5 8/1/2014 13 NULL 22 NULL
5 8/1/2014 12 NULL 23 NULL
5 8/1/2014 13 NULL 23 NULL
6 NULL 14 06/01/2014 24 NULL
7 NULL 15 NULL 25 09/01/2014
Desired Output
a.id b.id c.id date
3 11 21 07/01/2014
5 12 22 08/01/2014
5 13 22 08/01/2014
5 12 23 08/01/2014
5 13 23 08/01/2014
6 14 24 06/01/2014
7 15 25 09/01/2014
Upvotes: 1
Views: 42
Reputation: 1271051
Just use coalesce()
:
select a.id, b.id, c.id, coalesce(a.date, b.date, c.date) as date
Upvotes: 1
Reputation: 25763
You are looking for coalesce
funtcion
select a.id,bid,c.id,
coalesce(a.date,b.date,c.date) as date
from ...
Upvotes: 1