Skip to content

Instantly share code, notes, and snippets.

@Hotfirenet
Created January 19, 2018 10:14
Show Gist options
  • Save Hotfirenet/041b29ff3f32db6ca009be8ea900f4ab to your computer and use it in GitHub Desktop.
Save Hotfirenet/041b29ff3f32db6ca009be8ea900f4ab to your computer and use it in GitHub Desktop.
Mysql UPDATE, SELECT With SUM
UPDATE ps_affiliate A
INNER JOIN
(
SELECT id_order, SUM(product_quantity) AS nb_article_order
FROM ps_order_detail
GROUP BY id_order
) B
ON B.id_order = A.id_order
SET A.nb_article_order = B.nb_article_order
@Hotfirenet
Copy link
Author

UPDATE ps_affiliate A
INNER JOIN
(
SELECT id_affiliate, MAX(date_add) AS date_lastUpd
FROM ps_affiliate_history
GROUP BY id_affiliate
) B
ON B.id_affiliate = A.id_affiliate
SET A.date_lastUpd = B.date_lastUpd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment