Question: I have table with two FK `UserProfile_Id` and `Service_Id`. This table contains bit field which value I need to change. 

I have two temporary tables:

First table **#temp2**:

```
EmailAddress,
UserProfile_Id

```

Second table **#temp**:

```
EmailAddress,
Service_Id

```

This statement does not work:

```
UPDATE MailSubscription SET BitField=1
where UserProfile_id IN ( SELECT UserProfile_Id from #temp2 ) 
      and Service_id IN ( SELECT ServiceId from #temp)

```

I know why it does not work, but have no idea how to fix it to work fine. 

I need to change `bitField` for `MailSubscription` where **tuple**(UserProfile\_Id,Service\_Id) is in joined #temp and #temp2, but I can not write it like this in mssql.

Answer: 
```
UPDATE M
SET M.BitField=1
from MailSubscription M
inner join #temp2 t2 on M.UserProfile_id=t2.UserProfile_Id
inner join #temp t on M.Service_id=t.ServiceId
and t.EmailAddress=t2.EmailAddress

```
```
UPDATE MailSubscription SET BitField=1
FROM #temp2
JOIN #temp on #temp2.EmailAddress=#temp.EmailAddress
WHERE MailSubscription.Service_id = #temp.ServiceId 
  AND MailSubscription.UserProfile_id =  #temp2.UserProfile_Id 

```