SQL Server - How to update a column with another tables columns value?

Asked By Donna Karan on 30-Dec-13 07:20 PM

I have two tables "basket_products" and "products". I want to update "products" table's "adet" column with "basket_products" "adet" column. And i want to update rows where basket_products.urun = products.urun. I want to use this code and getting error : "The multi-part identifier "basket_products.urun" could not be bound."

update products set adet = adet - ( select basket_products.adet from basket_products inner join products on products.urun = basket_products.urun) where products.urun = basket_products.urun

What's wrong?

Robbe Morris replied to Donna Karan on 30-Dec-13 09:09 PM
update products
 set adet = adet - isnull((select adet from basket_products where urun = products.urun),0)