Joining tables using OR condition

  • I am told that i need to join
    Select * from Table A
    Left Join Table B
    on A.part OR A.part2 = B.Part

    Can i do that?  having a challenge doing it.

    thanks, as always

  • you need to go and read the manuals in more detail - and google as there are plenty of good examples.

    This is a beginners question.

    ... a join b
    on a.part = b.part
    or a.part2 = b.part

  • thanks!  much appreciated.

  • jeffshelix - Thursday, November 15, 2018 2:56 PM

    Please don't use SELECT * in production code. I also hope you know table is reserved word and can't be used the way you tried. SQL has the IN() predicate, which we stole from Pascal. While it doesn't apply in this case you will find many SQL implementations to special optimizations for it.

    SELECT * --- bad code
    FROM Foo AS A
       LEFT OUTER JOIN
       Bar AS B
       ON B.part_name IN (A.part_name, A.part2_name);

    Please post DDL and follow ANSI/ISO standards when asking for help. 

Viewing 4 posts - 1 through 3 (of 3 total)

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