Reputation: 191
Here, I have some student Information In table. Whose authorized value is by default 0. After checking some condition i group some students and update there value to 1.
Only those students who meets the given condition i.e.
select * from studentA
where schName ='IES DADAR' and lang = 'E'
[1]: http://rk.somee.com/untitled.jpg
I am trying with the following code but its not filtering as per my given condition, instead it changes every students authorization value to 1.
update studentA
set Authorized = '1'
where Authorized IN
( select Authorized from studentA
where schName ='IES DADAR' and lang = 'E')
You can suggest me another method as well.
Upvotes: 0
Views: 1917
Reputation: 10484
The subquery
select Authorized from studentA
where schName ='IES DADAR' and lang = 'E'
returns 0 and so your actual query becomes
update studentA
set Authorized = '1'
where Authorized IN ('0')
thereby updating every row in the table.
So, it should be
update studentA
set Authorized = '1'
where schName ='IES DADAR' and lang = 'E'
Upvotes: 2
Reputation: 204766
try
update studentA
set Authorized = '1'
where schName ='IES DADAR'
and lang = 'E'
Upvotes: 3