dimanche 3 mai 2015

SQL - How to join two tables using values from the other table for missing or null values in either table

Alright StackOverflow, I have a problem:

I am doing some work with Azure Machine Learning and I have reached an impasse. I have two tables, and I need to join them. The tables look like this:

   TABLE A          TABLE B   
+-----------+    +-----------+
| a | b | c |    | a | b | c |
+-----------+    +-----------+
| 1 | 2 |   |    |   | 2 | 3 |
+-----------+    +-----------+

(those are just examples.)

I need to join these tables when columns they share (in this case only b, but could be multiple) are equivalent. I also, however, need to populate missing values. If TABLE A is missing a value for one of its columns, and TABLE B has it for a matching row, they should combine values in the result table. I know that there is a way to do this one way, but it also needs to work in reverse, so that if TABLE B is missing a value, and TABLE A has one, it is populated.

Some background information:

  • AzureML uses a form of SQLite for their SQL interpretation, so please try and keep your answers in as basic SQL as possible. Thanks! :)
  • AzureML has a built in join module, for those familiar with AzureML, but I don't think it'll be able to accomplish what is necessary. I'll use the SQL interpretation module.

Your assistance is appreciated! Thanks!

Aucun commentaire:

Enregistrer un commentaire