title: Update multiple rows with the select statement : SQL Server
body: <p>An old problem I see, but after two days looking around, I just couldn't fix it. I have two tables:
  employee and random_values</p>
  
  <p>employee has one column: emp_no with 3000 rows</p>
  
  <p>random_values has one column: rand_val with 100 rows</p>
  
  <p>I am trying to replace 100 rows in emp_no with 100 rows from rand_val.</p>
  
  <p>I have the following:</p>
  
  <pre><code>UPDATE employee
  SET employee.emp_no=random_values.rand_val
     FROM random_values
  WHERE employee.emp_no IN (SELECT emp_no FROM employee
                  GROUP BY emp_no HAVING COUNT(*)&gt;1)
  </code></pre>
  
  <p>Results: After running the emp_no gets 100 rows OF THE SAME VALUE, namely the first value from rand_val</p>
  
  <p>Goal: emp_no should get 100 DIFFERENT rows from rand_val</p>
  
  <p>Any help is appreciated. Thanks.</p>