Reputation: 29
I have a table like this:
items
id old_new object
1 o pen
2 n house
3 o dog
4 o cat
5 n carrot
I would like the select return:
id new_object old_object
1 null pen
2 house null
3 null dog
4 null cat
5 carrot null
Do I need to use an outer join on the same table?
Upvotes: 0
Views: 56
Reputation:
No join needed:
select id,
case when old_new = 'n' then object end as new_object,
case when old_new = 'o' then object end as old_object
from the_table
order by id;
Upvotes: 2