0

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?

1 Answer 1

2

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;
Sign up to request clarification or add additional context in comments.

1 Comment

How would this get the results OP wants? It would just return the old_new column wich is just N or O

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.