title: SQL Server MERGE statement and ORDER BY clause
body: <p>I would like to write a MERGE statement to pick TOP 10 rows from a large table by using ORDER BY clause and update it’s one of the column values. MERGE statement allows me to pick TOP 10 rows but I could not put ORDER BY clause anywhere. </p>
  
  <pre><code>MERGE TOP(10) StudentAllocation AS SA
  USING (SELECT @sub_id AS subId) AS TSA ON SA.sub_id = TSA.subId
  WHEN MATCHED THEN 
         UPDATE SET SA.exam_batch = 1);
  </code></pre>