SQL UPDATE WHERE IN (List) or UPDATE each individually?

43    Asked by MattDyer in SQL Server , Asked on Aug 16, 2025

How should you update multiple rows in SQL—by using a single UPDATE ... WHERE IN (list) statement or by updating each row individually? What are the differences in performance, readability, and best practices between these two approaches?

Answered by Rose Black

When you need to update multiple rows in SQL, you generally have two choices: use a single UPDATE ... WHERE IN (list) query or update each row individually with separate UPDATE statements. Both approaches work, but they have different trade-offs in terms of performance, readability, and maintainability.

Using UPDATE ... WHERE IN (list)

 UPDATE employees

SET status = 'Active'

WHERE id IN (101, 102, 103);

  • Updates multiple rows in a single query.
  • More efficient since the database engine processes it in one operation.
  • Easier to maintain and cleaner code when applying the same update across multiple rows.

Updating Each Individually

  •  UPDATE employees SET status = 'Active' WHERE id = 101;
  • UPDATE employees SET status = 'Active' WHERE id = 102;
  • UPDATE employees SET status = 'Active' WHERE id = 103;
  • Executes multiple queries, which increases overhead.
  • Less efficient for large datasets since each update requires a separate database call.
  • Only useful if each row needs a different value (e.g., updating salaries or names with unique values).

Best Practice:

  • If all rows get the same update, use a single UPDATE ... WHERE IN for performance and readability.
  • If different rows need different values, consider:
  • Using a CASE statement in a single query.
  • Or creating a temporary table with the new values and joining it in an UPDATE.

In short, UPDATE ... WHERE IN (list) is almost always better for bulk updates, while individual updates should only be used when values differ per row.



Your Answer

Interviews

Parent Categories