← Back to list

MSSQL Concepts I

1. UPDATE query usage with JOINS

11 · 2025-10-12 04:39 · 0 claps · 1.1 min read
#data-science #mssql #sql #mssql-server #data-analysis
Open on Medium ↗
Wiki topics: ML · Machine Learning 🔬 · Science · General

MSSQL Concepts I

1. UPDATE query usage with JOINS

USE: When table A is updated based on values and conditions of another table B.

How it works:

UPDATE target_table
SET target_table.column = soource_table.column
FROM target_table
JOIN source_table ON target_table.id = source_table.id
WHERE condition_s;

Key points:

  • Only the table after UPDATE is getting modified. (here its target_table)
  • No other table in the join gets modified.
  • You can use any type of join (INNER, LEFT, RIGHT)

Real World Use Cases:

  1. Updating prices from a staging table ( When importing nnew pricing data, you need to update existing products:
  2. Calculating aggregates from Child Records (Updating order totals based on update items):
  3. Copying data between related tables (Updating Customer status based on their recent activity):
  4. Updating based on multiple table conditions (Setting employee salaries based on department & performance):
  5. Updating with LEFT JOIN — Handling NULLs (Marking products as discontinued if they have no recent sales):
  6. Data Cleanup / Normalization (Updating denormalized data to match the source of truth):

Important Considerations:

PERFORMANCE:

  • Always ensure proper indexes on join columns.
  • Use WHERE clause to limit rows updated.
  • Consider Batch updates for large tables

FOLLOW _ UP QUESTIONS : What is batch update ?

SAFETY:

  • Test with SELECT first to verify which rows will be affected.
  • Use transactions for critical updates.
  • Be careful with LEFT JOINS setting NULL values.

ALTERNATIVES ( upcoming)


메타데이터
post_id
b42ab70c4ffb
slug
mssql-concepts-i-b42ab70c4ffb
url
https://medium.com/@opt_eleven/mssql-concepts-i-b42ab70c4ffb
canonical_url
https://medium.com/@opt_eleven/mssql-concepts-i-b42ab70c4ffb
author_url
https://medium.com/@opt_eleven
status
ok
fetched_at
2026-06-09 15:37:30