using 'OR CLAUSE' in LEFT OUTER JOIN

  • I have written a left outer join and in the ON CLAUSE I have used an OR CONDITION also

    select *

    from table A

    left outer join table B on (table A.col1 = tableB.col1 OR table.col1 IS NULL) AND

    (table A.col2 = tableB.col2)

    The use of OR has seriously hampered the preformance.

    Is there an alternative to obtain the same objective differently.

    my solution -

    i was planning to split the query using 'UNION ALL' and perform left outer join two times

    select *

    from table A

    left outer join table B on (table A.col1 = tableB.col1 AND table A.col2 = tableB.col2)

    UNION ALL

    select *

    from table A

    left outer join table B on (table B IS NULL AND table.col1 IS NULL)

  • Using UNION ALL is certainly a step in the right direction. Without having a better understanding of the structures and data it is hard, at least for me, to go beyond that.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply