i need to update the table based on the two user.
for eg:
update table1 set rating=@rate where User1=@userid / user2=@userid
so i need to write a single query which satisfy the condition for both the users user1 and user2.
if i pass the @userid ,if it matches the user's id it should update user1 record. if the i开发者_如何学God whcih i pass is user2's id then it should update the user2 rec.
How to check for this condition in a single query.......
any idea????????
if user1 and user2 are different fields, then
update table1 set rating=@rate where (User1=@userid and User2<>@userid) or (User1<>@userid and user2=@userid)
update table1 set rating=@rate
where User1=@userid OR
user2=@userid
I don't totally understand what you're asking - assuming you have a table with two id's, user1
and user2
, and you want to update that row when @userId
matches either of the two, you could use:
update table1
set rating = @rate
where (user1 = @userid or user2 = @userid)
Is that what you're looking for?? Or am I misunderstanding your question? If so: please clarify! Maybe show us your table structure or something to help our understanding.
精彩评论