Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to avoid using MAX(CASE..WHEN) in a subquery

mayloFeb 10 2016 — edited Feb 10 2016

hi everyone, for all of you plsql gurus I have a question:

SELECT a.id,

     a.name,

     b.name,

     ....

     (CASE WHEN sub_c.value_c = '2015' AND a.code >= 1111 THEN 'Output value is ' || a.value_a ELSE 'Random value' END) output

FROM table_a a,

     table_b b,

     ...

     (SELECT c.a_id

          MAX(CASE WHEN c.code <> 'A'

                    THEN c.value

                     END) value_c

     FROM table_c

     GROUP BY c.a_id

     ) sub_c

WHERE a.id = b.a_id

AND a.id = sub_c.a_id  ( + )

So they want all a_id from table_c, and if WHEN condition is not satisfied they still want that a_id even with NULL for value_c.

I've tried to outline the most important parts, so the question is: is there a way to avoid using this MAX-CASE construct to speed this query up a little?

Thanks a ton to anyone who bothered to look at this!

This post has been answered by Paulzip on Feb 10 2016
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 9 2016
Added on Feb 10 2016
2 comments
337 views