I’m trying to update a table based upon the user id from another table. I’ve come across the Update from syntax but I’m struggling to write my query correctly.
The below code should show you what I’m attempting to do. When i run it i get 0 rows affected.
update jared_test
set user_count = 1
from new_user nuj
inner join (select us.userID
from users us
where us.email = 'j@j.co.uk') u on nuj.userid = u.userid
/********EDIT*******************\
I discovered there was a problem with my Cursor loop that was preventing this from working, so this does actually work. However I’d be interested if a where is better than a from in this instance for optimisations.
I’m not 100% on why the other solutions are using a subselect which will perform slower than a regular join most often. Though taos subselect is essentially a regular join just written interestingly.