tags:

views:

297

answers:

5

Hi friends,

Here i am having a table, where status (initially progress) is a column in it. I need to update the status column into "success".

Shall i write a query like this?

Update "tablename" set status='success' where status='progress'

Why i'm asking means? here the update and its where condition are checking the same column.

Is it correct? Please clarify my doubt..

Thanks in Advance, Praveen J

+2  A: 

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.

paxdiablo
+2  A: 

That statement will change the value for each row where status was "progress" to "success". Is that really what you want?

tehvan
My question is - Is it work?, because here i have used the status for modifying and also in where condition.
praveenjayapal
Yes it will work
tehvan
yes its working, it confused - now i am clear. thank you.
praveenjayapal
+2  A: 

yes, that's correct, all rows where status = 'progress' will be updated

Jack
+2  A: 

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.

Chad Birch
+2  A: 

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

REA_ANDREW