ashish
ashish

Reputation: 239

query to avoid left outer join or inner join

I have table data like

value   pvalue  value_type
an1001  bk1001  1
an1002  null    1
an1003  null    1
an1004  bk1002  1
bk1001  ck1001  2
bk1002  ck1002  2
ck1001  MG1001  3
ck1002  null    3

I m expecting result like

value   pvalue1 pvalue2 pvalue2
an1001  bk1001  ck1001  MG1001
an1002  bk1002  ck1002  
an1003          
an1004          

is there any way to write queries where i can avoid left outer join or inner join rather that i can use inline queires

Upvotes: 0

Views: 223

Answers (1)

pkgajulapalli
pkgajulapalli

Reputation: 1126

You can use something like the following query. Please mind the syntax errors, if any.

select value,
     max(case when value_type = 1 then pvalue else null end) as pvalue1,
     max(case when value_type = 2 then pvalue else null end) as pvalue2,
     max(case when value_type = 3 then pvalue else null end) as pvalue3
from table
group by value;

Upvotes: 1

Related Questions