Coding⏱️ 3 min read📅 2026-06-03

How to Fix: UPDATE from a SELECT

Update a table with SELECT statement using temporary values.

Quick Answer: Use an INSERT INTO...SELECT statement to populate the temporary table, then use UPDATE...SELECT to update the target table.

The issue you're encountering occurs when attempting to update a table using a SELECT statement. This is a common source of frustration among database administrators and developers alike.

This problem arises from the fact that SQL Server does not support updating a table directly with a SELECT statement, unlike its counterpart in other databases such as MySQL or PostgreSQL.

🔍 Why This Happens

  • The primary reason for this limitation lies in the way SQL Server handles data modification. The UPDATE command requires an explicit list of column names to be updated, whereas the SELECT statement only retrieves data without modifying it.
  • Another possible cause could be the presence of temporary tables or views that are being used to store and retrieve data.

🛠️ Step-by-Step Verified Fixes

Substitution with INSERT

  1. Step 1: To resolve this issue, you can use a workaround by inserting the retrieved values into the target table using an INSERT statement.
  2. Step 2: For example, if your SELECT statement is retrieving data from another_table where sql = 'cool', you can insert that data into Table as follows: INSERT INTO Table (col1, col2) SELECT col1, col2 FROM other_table WHERE sql = 'cool'
  3. Step 3: This approach ensures that the retrieved values are properly inserted into the target table without relying on an unsupported UPDATE statement.

Avoid using SELECT with UPDATE

  1. Step 1: A better approach would be to avoid using a SELECT statement directly in your UPDATE command.
  2. Step 2: Instead, you can use temporary tables or views to store and retrieve data before updating the target table.
  3. Step 3: For instance, you could create a temporary view that combines the data from other_table with the conditions specified in your WHERE clause.

✨ Wrapping Up

By understanding the root causes of this issue and applying the appropriate workarounds, you can effectively update tables using SELECT statements in SQL Server while maintaining data integrity and consistency.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions