Reputation: 13
I have an animals table and am trying to update the type of all dogs to be cats, and then make the existing cats to be dogs.
So far I have
UPDATE Animals
SET name='Cat'
WHERE name = 'Dog'
SET name = 'Dog'
WHERE name = 'Cat';
Upvotes: 0
Views: 38
Reputation: 1270683
You can handle both scenarios in one query:
UPDATE Animals SET name = (CASE WHEN name = 'Dog' THEN 'Cat' ELSE 'Dog' END)
WHERE name IN ('Cat', 'Dog');
Upvotes: 5
Reputation: 4192
Try three queries:
UPDATE Animals SET name = 'Animal' WHERE name='Dog';
UPDATE Animals SET name = 'Dog' WHERE name='Cat';
UPDATE Animals SET name = 'Cat' WHERE name='Animal';
Upvotes: 0