My table looks like this:
ID APPLICATION OTHERVALUE
0001 subapp SubvalueA
0001 mainapp MainValue1
0002 subapp SubvalueB
0002 mainapp MainValue1
0003 subapp SubvalueA
0003 mainapp MainValue2
I need all lines of subapp
, but then I also need value of OtherValue
when the application is mainapp
from same table where ID is the same. I'm using Oracle.
How can I build a query for this?
Expected result:
ID APPLICATION OTHERVALUE OTHERVALUE2
0001 subapp SubvalueA MainValue1
0002 subapp SubvalueB MainValue1
0003 subapp SubvalueA MainValue2
Best Answer
You can use an aggregate function and a
CASE
statement to get the data into this format:See SQL Fiddle with demo
Result: