Join on Multiple Criteria with Or Statement

3 followers
0
Avatar

I am wondering if there is a way to join two datasets with one column or another column (ie. match on customer code or on custmer name). It seems that if you specify multiple criteria in the join it is always an and statement. Thanks.

Joshua Barnett

4 comments

  • Avatar
    Sabeel

    Hi Joshua,

     

    Could you please provide some example of this problem statement, just to interpret this query accurately?

    Regards,

    Sabeel

    0
  • Avatar
    Joshua Barnett

    Below is an example. I need to join based on Customer Number or Customer Identifier to pull in the "data to be pulled in Join" column in the right table (left join). You can see sometime there is a match on only number or identifier in the original table. I do not see an easy way to accomplish this.

    0
  • Avatar
    Joel Stewart

    What do you expect the output to look like if a record matches both values? Is there any time where a record would match differently between the Customer Number and Customer Identifier? Also, what size are the data sets? This can influence how complex a solution should be versus how performant. 

    My initial thoughts are to join based on the Customer Number only. Independently join on the Customer Identifier. Then union these two sets and use grouping to eliminate potential duplicates. 

    1
  • Avatar
    Joshua Barnett

    This strategy should work. Thanks. The identifier and number should always be linked to the same person.

    0
Please sign in to leave a comment.