Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

Conditional column selecting column from other table

Hello all.

I need a help.

 

I have two tables:

Table A with customer by entity name

Table B with customer by entity name and short name

 

How can I add a conditional column in Table A selecting a column from Table B (entity name) with output from Table B (short name)? 

 

I don't have all customer in Table B, so I need also a condition that null returns the customer (entity name) from Table A.

 

 

Thanks!

 

 

 

  • Anonymous's avatar
    Anonymous
    7 years ago

    Anonymous 

    Got it! So you can merge the tables with a LEFT JOIN. Then you can create a new conditional column with the format:

    IF [new column] = null THEN output=Column1, ELSE [new column]

     

    ]

9 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Anonymous 

    You're going to want to have a column with a unique ID that you can use to join Table A and Table B. Then you can select "Merge Queries" in the query editor, match on the unique ID, and make sure that it is the Join Kind "Left Outer (all from first, matching from second)." That way, since Table B doesn't have all of the entries that Table A has, the short name column entries that don't have a match will be replaced with a null in your new, merged table.

    Is that what you want to do?

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi Anonymous 

       

      I also want to change the null that I will have in the merged table by the Customer name (entity name) from Table A.

      • Anonymous's avatar
        Anonymous
        Not applicable

        Anonymous 

        So do you have some customers in Table B that are not in Table A? If so, since you are using a left join, those customers would not appear in your merged table.