请帮我。如何从database2更新所有数据database1?
查询以更新此数据库
我有两个数据库:
1. database1,表产品:

================================
| model  | pricelow | pricehigh|
================================
| A2345  | 64       |   74     |
| A2350  | 50       |   60     |


database1

=====================================================
model_master | pricelow_master | pricehigh_master |
=====================================================
|A2345       | 70              |    80            |
|A2350       | 60              |    65            |

database2

最佳答案

您需要唯一的密钥进行更新。在这里我使用id

试试这个可能对您有帮助。

更新:

UPDATE database1 p, database2 pm SET
p.model = pm.model_master,
p.pricelow = pm.pricelow_master,
p.pricehigh = pm.pricehigh_master,
WHERE p.id = pm.id


对于插入:

INSERT INTO database1 (model, pricelow, pricehigh) SELECT model_master, pricelow_master, pricehigh_master FROM database2

10-06 08:11