Created
January 16, 2019 10:27
-
-
Save elizov/84ee887bb81bc0be2bfe188d50928d6e to your computer and use it in GitHub Desktop.
UPDATE FROM SELECT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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