使用SELECT作为WHERE更新

时间:2014-03-20 15:57:41

标签: mysql sql

我想运行一个更新,其中WHERE语句由2个SELECTS组成,这完全接近你的方式吗?

UPDATE Requests SET Response=1 WHERE 
sender=SELECT userID FROM Users WHERE Username=?) and 
Reciever = SELECT userID FROM Users WHERE Username=?

感谢!

1 个答案:

答案 0 :(得分:1)

你错过了括号,就是这样。

UPDATE Requests SET Response=1 WHERE 
sender = (SELECT userID FROM Users WHERE Username=?) and 
receiver = (SELECT userID FROM Users WHERE Username=?);