请帮帮我。如何从database2更新所有数据database1? 查询更新此DATABASE1 我有两个数据库: 1. database1,table product:
================================
| model | pricelow | pricehigh|
================================
| A2345 | 64 | 74 |
| A2350 | 50 | 60 |
database1
=====================================================
model_master | pricelow_master | pricehigh_master |
=====================================================
|A2345 | 70 | 80 |
|A2350 | 60 | 65 |
database2
答案 0 :(得分:1)
您需要一个唯一的密钥才能进行更新。我在这里使用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