Reputation: 38529
I have a table with a status column (initially with progress
). I need to update this column's value to success
.
Is this query what I want?
Update "tablename" set status='success' where status='progress'
The reason I am asking is that both the update and the where condition are checking the same column.
Is this correct?
Upvotes: 1
Views: 1247
Reputation: 881423
That will work but it will modify all rows that have progress in that column.
I think you probably want to limit the update based on some other part of the record.
For example if it were the progress of installing a particular piece of software (say Ubuntu on machine number 7):
update tbl set status='success'
where status='progress'
and machine_id = 7
and software = 'Ubuntu'
From a conceptual point of view, it's gathering the list of records to change first (with the where
clause), then applying the update ... set
to all those records.
Upvotes: 4
Reputation: 10764
Yes that is correct, identify the row/s you want to change and commit the information to the specirfifed columns:
Update MyTable set Allowed = 1 WHERE Allowed = 0 AND UserID = 123
Cheers,
Andrew
Upvotes: 3
Reputation: 74548
Yes, that's fine. That will update every row in the table that's "progress" to be "success" though, not only one. I'm not sure if that's what you want or not.
Upvotes: 2
Reputation: 1008
yes, that's correct, all rows where status = 'progress' will be updated
Upvotes: 2
Reputation: 10369
That statement will change the value for each row where status was "progress" to "success". Is that really what you want?
Upvotes: 2