title: Update query using Subquery in Sql Server
body: <p><strong>I have a simple table Structure like this:</strong></p>
  
  <p>Table <strong>tempData</strong></p>
  
  <pre><code>╔══════════╦═══════╗
  ║   NAME   ║ MARKS ║
  ╠══════════╬═══════╣
  ║ Narendra ║    80 ║
  ║ Ravi     ║    85 ║
  ║ Sanjay   ║    90 ║
  ╚══════════╩═══════╝
  </code></pre>
  
  <p>And I also have another table names as <strong>tempDataView</strong> like this</p>
  
  <pre><code>╔══════════╦═══════╗
  ║   NAME   ║ MARKS ║
  ╠══════════╬═══════╣
  ║ Narendra ║       ║
  ║ Narendra ║       ║
  ║ Narendra ║       ║
  ║ Narendra ║       ║
  ║ Ravi     ║       ║
  ║ Ravi     ║       ║
  ║ Sanjay   ║       ║
  ╚══════════╩═══════╝
  </code></pre>
  
  <p>I want to update the table <strong>tempDataView</strong> , by setting the <strong>Marks</strong>  according to the <strong>tempDataView</strong> - <strong>Name</strong> compared with <strong>tempData</strong> - <strong>Name</strong></p>
  
  <p>Yes let me show you what I tried, I tried to solve this using the Cursor and its solved perfectly, but I am finding the way to solve it using the <strong>Subquery</strong></p>
  
  <p>Here it is:</p>
  
  <pre><code>Declare @name varchar(50),@marks varchar(50)
  Declare @cursorInsert CURSOR
  set @cursorInsert = CURSOR FOR
  Select name,marks from tempData
  OPEN @cursorInsert
  FETCH NEXT FROM @cursorInsert
  into @name,@marks
  WHILE @@FETCH_STATUS = 0
  BEGIN
  UPDATE tempDataView set marks = @marks where name = @name
  FETCH NEXT FROM @cursorInsert
  INTO @name,@marks
  END
  CLOSE @cursorInsert
  DEALLOCATE @cursorInsert
  </code></pre>
  
  <p>Actually it's like the homework for me to solve it using the Subquery. </p>