Skip to content

Instantly share code, notes, and snippets.

@caovillanueva
Last active March 22, 2022 17:19
Show Gist options
  • Save caovillanueva/a04b3350d8de032f450b6f3d47a33ba3 to your computer and use it in GitHub Desktop.
Save caovillanueva/a04b3350d8de032f450b6f3d47a33ba3 to your computer and use it in GitHub Desktop.
[mysql update column from another table] Coping info from specific colum from another table. #mysql,#PS17
UPDATE ps_product_shop c
JOIN table_test e ON c.id_product = e.id_product
SET c.id_category_default = e.id_category_default
note: tested.
------------------------------------------------
UPDATE TableB
SET TableB.value = (
SELECT TableA.value
FROM TableA
WHERE TableA.name = TableB.name
);
NOTE: IT CANT BE THE SAME TABLE.Use this for just 1 data and small DB
---------------------------------------------------
Example with Join (more fast)
UPDATE tableB t1
INNER JOIN tableA t2
ON t1.name = t2.name
SET t1.value = t2.value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment