Reputation: 3237
I have two table source and target. Is it possible to perform following operation in single query?
If the row exists in both the source and target, UPDATE the target;
If the row only exists in the source, INSERT the row into the target;
If the row exists in the target but not the source,
DELETE the row from the target.
Upvotes: 2
Views: 955
Reputation: 167
You can't do it all in one query, but you can do it all in one transaction if you are using a transactional store engine (like InnoDB). This might be what you want,
START TRANSACTION;
INSERT...; DELETE... UPDATE...;
COMMIT;
Upvotes: 2