mercredi 5 août 2015

Insert Data from Table A to Table B WHERE (conditions) & SET Col.a = "xxx"


| Table [A]                | Table [B]   
| id    value   data       | id    value   data
| ab     15      100       | ac     19      200
| ab     18      101       | ac     28      310
| ab     22      199       | ac     39      401

Table A is my old database table with history data. Table B is my current database table with corrected value in id

I'll like to insert historic data from Table A into Table B WHERE value<=xxxx AND value >=xxxx and also at the same time set the data from tablea.id = ac when inserted into Table B so the data outcome will be.

| Table [A]                | Table [B]   
| id    value   data       | id    value   data
| ab     15      100       | ac     19      200
| ab     18      101       | ac     28      310
| ab     22      199       | ac     39      401
|                          | ac     15      100
|                          | ac     28      101
|                          | ac     22      199

I'll be using INSERT IGNORE as my table has 3 column as it's composite primary key. Table description is just a sample. My table has alot more columns just highlighting the main difference for the data import I want to accomplish.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire