user2192283
user2192283

Reputation: 3

select statement - update the value of one field with a fixed value

I have a select statement that returns a few fields from a table.

I want to update only the results of that select, giving a fixed value in one field.

I though of that, but it doesn't work:

UPDATE

 (SELECT * from table.... where...)

SET field1=1

Upvotes: 0

Views: 1124

Answers (2)

ljh
ljh

Reputation: 2604

If your are using t-sql

UPDATE 
SET field = fixed value
from tablename
where filed....

Upvotes: 0

Mahmoud Gamal
Mahmoud Gamal

Reputation: 79979

You didn't need a SELECT, just use a WHERE clause directly with the UPDATE to do this only for the rows that statify the condition in the WHERE clause:

UPDATE t
SET field1 = 1
FROM table AS t
WHERE ...

Upvotes: 2

Related Questions