0

I have 2 tables on MySQL. Im looking for a way to insert the cifStore in the operation table.

What i want (if possible) is to create a query that sets some kind of relation between the idStore from both tables and then copy the corresponding the cifStore values from the store table, to the operation table on cifStore column.

       operation                              store

|idOper|idProv|idStore |cifStore |      |idStore|cifStore|storeName| 
|10101 |m01   |s01     |         |      |s01    |A205075 |ret10    |
|..    |..    |...     |...      |      |..     |..      |...      |

The expected result for the above example, would be something like:

        operation                              

|idOper|idProv|idStore |cifStore |      
|10101 |m01   |s01     |A205075  |     
|..    |..    |...     |...      |
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
bobtuozzo
  • 15
  • 2
  • 1
    Why, that would cause duplication! you have the `idStore` so you can get the `cifStore` in any query by using a simple JOIN? – RiggsFolly Sep 03 '19 at 13:29

1 Answers1

0

Try an update join:

UPDATE operation op
INNER JOIN store s
    ON op.idStore = s.idStore
SET
    op.cifStore = s.cifStore;
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360