---
title: "How do I UPDATE from a SELECT in SQL Server?"  
description: "How do I UPDATE from a SELECT in SQL Server?"  
author: "Revati S Misra"  
published: 2023-07-11  
updated: 2023-07-12  
canonical: https://www.mindstick.com/forum/159023/how-do-i-update-from-a-select-in-sql-server  
category: "mssql server"  
tags: ["mssql server", "sql server", "sql"]  
reading_time: 2 minutes  

---

# How do I UPDATE from a SELECT in SQL Server?

How do I [UPDATE](https://www.mindstick.com/forum/156353/what-is-hummingbird-update) from a [SELECT](https://www.mindstick.com/forum/160534/orderby-then-select-vs-select-then-orderby-performance) in [SQL Server](https://www.mindstick.com/articles/12999/what-is-table-valued-function-in-sql-server)?

## Replies

### Reply by Aryan Kumar

To update from a select in [SQL](https://www.mindstick.com/articles/13115/types-of-keys-in-sql-or-oracle-database) [Server](https://www.mindstick.com/articles/43769/what-is-serverless-architecture-is-it-worth-switching-over), you can use the `UPDATE` statement with the `FROM` clause. The `UPDATE` statement allows you to update rows in a table, and the `FROM` clause allows you to select rows from another table.

The syntax for updating from a select in SQL Server is as follows:

SQL

```plaintext
UPDATE table_name
SET column1 = value1,
    column2 = value2,
    ...
FROM table1
WHERE condition;
```

The `table_name` is the name of the table that you want to update. The `column1`, `column2`, etc. are the columns that you want to update. The `value1`, `value2`, etc. are the new values for the columns. The `table1` is the name of the table that you want to select from. The `condition` is an optional clause that specifies the rows that you want to update.

For example, the following code will update the `CustomerName` column in the `Customers` table to `John Smith` for all customers where the `CustomerID` is 100:

SQL

```plaintext
UPDATE Customers
SET CustomerName = 'John Smith'
FROM Customers
WHERE Customers.CustomerID = 100;
```

This code will first select the row from the `Customers` table where the `CustomerID` is 100. Then, it will update the `CustomerName` column in the `Customers` table to `John Smith` for the selected row.

You can also use the `FROM` clause in the `UPDATE` statement to select rows from another table and update the rows in the current table based on the selected rows. For example, the following code will update the `CustomerName` column in the `Customers` table to the value of the `CustomerName` column in the `Orders` table for all customers who have placed an order:

SQL

```plaintext
UPDATE Customers
SET CustomerName = Orders.CustomerName
FROM Customers
JOIN Orders
ON Customers.CustomerID = Orders.CustomerID;
```

This code will first join the `Customers` and `Orders` tables on the `CustomerID` column. Then, it will update the `CustomerName` column in the `Customers` table to the value of the `CustomerName` column in the `Orders` table for all rows where the `CustomerID` is the same in both tables.


---

Original Source: https://www.mindstick.com/forum/159023/how-do-i-update-from-a-select-in-sql-server

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
