Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Check for MERGE in two columns

Hello - I have some cases where I need to check for a value in two different columns because one of them might be missing it, and then pick the value as one does in Merge.

 

For example, merge Query A and Query B.

QA has columns A1 and A2. QB has columns B3 and B4.

Now my merge condition is, match A1 and B3, and pick up the value in B4 (like a simple merge) but if A1 and B3 do not match, then check A2 and B3, and pick up value in B4.

 

Is this possible to do in same Merge Queries step? Otherwise I keep having to make two steps, and then picking common value after expanding the results of both Merge Queries..

 

Thanks!

  • Yeah, you cannot do that. You can match where A1 and B3 match and the same time A2 and B3 (so two joins) but you cannot do an if condition like that. Your best bet is to do two merges, expand both, then pick the first result unless it is null (no match), and get the second result if the first was null, which is I think what you've suggested, so you have your head around it it seems.

1 Reply

  • edhans's avatar
    edhans
    Community Champion

    Yeah, you cannot do that. You can match where A1 and B3 match and the same time A2 and B3 (so two joins) but you cannot do an if condition like that. Your best bet is to do two merges, expand both, then pick the first result unless it is null (no match), and get the second result if the first was null, which is I think what you've suggested, so you have your head around it it seems.