Hi there,
I have a requirement where I run a query and depending on one of the conditions I need a different set of columns returned, and each of the columns is in a different row. i.e.
table1
id key val
2 2_1 val2_1
2 2_2 val2_2
5 5_1 val5_1
5 5_2 val5_2
5 5_3 val5_3
5 5_4 val5_4
Then I'd like something like this:
select val from table1
where if id = 2 then return val where key in ('2_1', '2_2') else
if id = 5 then return val where key in ('5_1', '5_2', '5_4') else
if id = ....
The output for instance I'd expect if id=5 is:
val5_1, val5_2, val5_4
I need to be able to manually put which values to return for each id. I don't necessarely need all values of an id.. for instance I left out val5_3 where id = 5.
Is this possible? I have like 20 ids, and it's either doing something like this or create 20 specific queries. Please let me know if more clarification is needed.
Thanks,