Can I combine two queries like this
first: UPDATE table SET col1=1 WHERE id='x';
second: UPDATE table SET col1=0 WHERE id='y';
can I join these queries in one?
UPDATE table
SET col1 = CASE id WHEN 'x' THEN 1 ELSE 0 END
WHERE id IN ('x','y')
Use this sql query:
UPDATE table
SET col1 =
CASE id
WHEN 'x' THEN 1
WHEN 'y' THEN 0
END
WHERE id IN ('x','y');
Also see Multiple Updates in MySQL