I’m not sure how to concisely formulate question to describe a problem I would like to solve.
I have two following tables:
Table 1
[idA] [numA]
NULL 8
1 10
2 15
3 16
Table 2
[idB] [numB]
2 14
3 30
4 32
Now, I’m not sure how to formulate T-Sql query to produce following result:
[id] [numA] [numB]
NULL 8 0
1 10 0
2 15 14
3 16 30
4 0 32
Are there any suggestions on how to solve this?
UPDATE:
Would there be any problems with @AdaTheDev’s script if there was one more table (idC, numC) to join? In that case what would be the best solution? The thing is I have 15 of them to join into one table and they should be grouped by id and have 15 corresponding numX columns.
Something like this, should do it
Update
Note I’ve added an OR condition to the join to handle the case where idA and idB are NULL, to give a single result
Full test script (with added NULL id record in table2):