What's best performance wise, two separate
UPDATE table1 SET enabled = 0 WHERE code NOT IN ( SELECT id FROM table2 ); UPDATE table1 SET enabled = 1 WHERE code IN ( SELECT id FROM table2 );
Or a single
UPDATE with a CASE?
UPDATE table1 SET enabled = ( CASE WHEN code IN (SELECT id FROM table2) THEN 1 ELSE 0 END );
(and let's consider there are no NULL values in the relevant columns).
What would perform best, supposed
id columns have are indexed?
I can't really tell because I don't have significant tables, and the only difference
EXPLAIN gives is that the former version uses the
WHERE (but I analyzed only one
UPDATE) - I'd say that a plus, but I'm unsure if that's enough.
I'm working with MySQL.