Skip to content

Instantly share code, notes, and snippets.

@elizov
Created January 16, 2019 10:27
Show Gist options
  • Save elizov/84ee887bb81bc0be2bfe188d50928d6e to your computer and use it in GitHub Desktop.
Save elizov/84ee887bb81bc0be2bfe188d50928d6e to your computer and use it in GitHub Desktop.
UPDATE FROM SELECT
UPDATE user_assets AS ua
INNER JOIN (
SELECT
ua.user_id,
ua.instance_id,
uas.state,
uas.payload,
uas.history
FROM user_assets AS ua
LEFT JOIN user_asset_states AS uas ON uas.user_id = ua.user_id AND uas.instance_id = ua.instance_id
WHERE
uas.state IS NOT NULL
OR uas.payload IS NOT NULL
OR uas.history IS NOT NULL
) AS t ON t.user_id = ua.user_id AND t.instance_id = ua.instance_id
SET
ua.state = t.state,
ua.payload = t.payload,
ua.history = t.history
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment