samedi 24 octobre 2020

How to join data from 2 tables based on multiple conditions in SQL

I have two tables as below.

Table1

Table2

I would want to get a new column with the data from table1 based on the condition using table2.

I am trying to get output something like this.

if(table1.codes contains table2.level1) give me table2.level1 else give me table2.level0 as "newcode"

with what I have tried, I am getting the table1.codes showing twice as it is matching both the level1 and level0 as in table3. I would want only one value of the codes to be present and match to both the level0 and level1.

table3

Aucun commentaire:

Enregistrer un commentaire