从另一个表列的最低值更新表列

  • 本文关键字:更新 最低值 另一个 php mysql
  • 更新时间 :
  • 英文 :


table1:

ID |  SKU | Images
------------------
1  | 1502 | Link1
2  | 1852 | Link2
3  | 1745 | Link3

table2:

ID | Product | MainLink
------------------------
1  | 1501    | Link1
2  | 1502    | Link1
3  | 1852    | Link2
3  | 1745    | Link3

我试图从table1中更新SKU,而table2

中每个主链接的最低值

结果是:

table1:

ID |  SKU | Images
------------------
1  | 1501 | Link1
2  | 1852 | Link2
3  | 1745 | Link3

这是我到目前为止的查询

UPDATE Table1 t1 JOIN Table2 t2 ON t1.Images = t2.MainLink SET t1.SKU = t2.Product

尝试以这种方式:

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

最新更新