Skip to content

Instantly share code, notes, and snippets.

@syn-arch
Created January 5, 2022 06:58
Show Gist options
  • Save syn-arch/3b60314f2780ce9b9398e5ae726f3278 to your computer and use it in GitHub Desktop.
Save syn-arch/3b60314f2780ce9b9398e5ae726f3278 to your computer and use it in GitHub Desktop.
mysql update column with value from another table
UPDATE tableB
INNER JOIN tableA ON tableB.name = tableA.name
SET tableB.value = IF(tableA.value > 0, tableA.value, tableB.value)
WHERE tableA.name = 'Joe'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment