Can I perform an UPDATE operation using a SELECT statement in SQL Server?

In SQL Server, there is a method to add records to a table with an <code>INSERT.. SELECT</code> command. Here’s an example of how that works:

INSERT INTO YourTable (columnA, columnB, columnC)
SELECT columnA, columnB, columnC
FROM AnotherTable
WHERE condition = 'example'

Could you let me know if it’s feasible to use a <em>SELECT</em> statement for updating records in a table? I have a temporary table with data that I need to use to modify another table. A hypothetical example would look like this:

UPDATE YourTable
SET columnA = NewValues.columnA, columnB = NewValues.columnB
FROM NewValues
WHERE YourTable.id = NewValues.id

Any guidance on this would be appreciated!

Yes, you can totally do this in sql server. You can JOIN the tables in the UPDATE statement just like in a SELECT query. It’s super useful for updating multiple records at once using data from another table! Just make sure your WHERE clause is correct to avoid altering wrong data.