|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
update TABLE set COLUMN_A = 0 FROM TABLE where EXISTS (select TOP 1 * from
TABLE where ID = 1 order by row desc) My TABLE includes the following data: ROW ID COLUMN_A 1 1 1 2 1 1 3 1 1 4 2 1 5 2 1 6 2 0 Trying to change ROW 3 column A = 0 The above query is changing all COLUMN_A values to 0. Sub query on it own identifiys the row no problem. Where am i going wrong ? Thank you for any . |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
There is no correlation between the subquery and the table you want to
update. This is why all rows are updated. Try this: UPDATE Table SET column_a = 0 WHERE id = 1 AND row = (SELECT MAX(T.row) FROM Table AS T WHERE T.id = Table.id); -- Plamen Ratchev http://www.SQLStudio.com |
|
![]() |
| Outils de la discussion | |
|
|