sql - How to use CASE here? -


i have table having 6 columns(a,b,c,d,e,f). if fixed column, lets d not null, want fetch 3 columns d,e,f; else if d null want fetch other 3 columns a,b,c.

am trying use not able proceed.

select      case when d not null      select d, e, f     else     select a,b,c       end mytable. 

any pointers?

you can check in each column:

select     case when d not null d else end,     case when d not null e else b end,    case when d not null f else c end mytable 

or use union

select a,b,c mytable d null union select d,e,f mytable d not null 

Comments

Popular posts from this blog

Why can rails not find a route created by a helper? -

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -