表1:
ID | SKU | Images
------------------
1 | 1502 | Link1
2 | 1852 | Link2
3 | 1745 | Link3
表2:
ID | Product | MainLink
------------------------
1 | 1501 | Link1
2 | 1502 | Link1
3 | 1852 | Link2
3 | 1745 | Link3
我正在尝试使用表2中每个MainLink的最低值来更新Table1中的SKU
结果将是:
表1:
ID | SKU | Images
------------------
1 | 1501 | Link1
2 | 1852 | Link2
3 | 1745 | Link3
这是我到目前为止的查询,但id没有得到我最低的值:
UPDATE Table1 t1 JOIN Table2 t2 ON t1.Images = t2.MainLink SET t1.SKU = t2.Product
答案 0 :(得分:0)
尝试这种方式:
UPDATE Table1 t1
JOIN (SELECT MIN(Product) Product, MainLink
FROM Table2 GROUP BY Table2.MainLink
) t2 ON t1.Images = t2.MainLink SET t1.SKU = t2.Product