2012-08-12 66 views
0

在這裏,我有一些學生信息表中。誰授權值默認爲0。 檢查一些條件我組的一些學生和更新也值爲1使用嵌套選擇查詢更新查詢

只有那些學生誰符合一定條件即

select * from studentA 
where schName ='IES DADAR' and lang = 'E' 

[1]: http://rk.somee.com/untitled.jpg 

我用下面的嘗試之後代碼,但它不是過濾按我給出的條件,而不是它的變化的每一個同學的授權值設置爲1

update studentA 
set Authorized = '1' 
where Authorized IN 
(select Authorized from studentA 
where schName ='IES DADAR' and lang = 'E') 

你可以建議我的另一種方法爲好。

回答

3

嘗試

update studentA 
set Authorized = '1' 
where schName ='IES DADAR' 
and lang = 'E' 
+0

感謝您的幫助 – 2012-08-12 21:45:20

2

子查詢

select Authorized from studentA 
where schName ='IES DADAR' and lang = 'E' 

返回0,因此您的實際查詢變得

update studentA 
set Authorized = '1' 
where Authorized IN ('0') 

從而更新表中的每一行。

所以,它應該是

update studentA 
set Authorized = '1' 
where schName ='IES DADAR' and lang = 'E' 
+0

thanx的詳細說明。有效。 – 2012-08-12 21:45:55