Skip to content

Instantly share code, notes, and snippets.

@jimytc
Created March 24, 2016 16:35
Show Gist options
  • Save jimytc/f11c3d31b7d7212917ff to your computer and use it in GitHub Desktop.
Save jimytc/f11c3d31b7d7212917ff to your computer and use it in GitHub Desktop.
Use INSERT with LEFT JOIN to achieve UPSERT
INSERT INTO creation_metadata (creation_id, category)
SELECT creations.id, creations.type
FROM creations
LEFT JOIN creation_metadata
ON creations.id = creation_metadata.creation_id
WHERE creations.type IS NOT NULL
AND creation_metadata.category IS NULL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment