user3671271 user3671271 - 3 months ago 7
SQL Question

How can i write update query for check this plan?

i'm new in database and can write very simple query ,i have two table:

table Maintable with this design:

enter image description here


And table karkard with this design:

enter image description here


want to write this update query in sql server:


update table MainTable
set score=score+karkard.karkard
where maintable.phone=karkard.phonenumber




How can i write that query?thanks all

Answer

This is a simple UPDATE query unless I'm missing something in your question:

UPDATE MainTable
  SET  score = mt.score + k.karkard
  FROM MainTable mt
    INNER JOIN karkard k ON k.phonenumber = mt.phone