adn
adn

Reputation: 430

query case when postgresql

I have query like this :

select
    case when code=31 then name end as name1,
    case when code=32 then name end as name2
from master where code=31 or partner_id=32

and the result just like this :

query result

I want to make just 1 row but 2 column which is the value is like the table above.

Anyone can help me? Thanks

Upvotes: 0

Views: 82

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269443

Use aggregation:

select max(case when code=31 then name end) as name1,
       max(case when code=32 then name end) as name2
from master
where code = 31 or partner_id = 32;

Upvotes: 1

Related Questions