title: How can I remove duplicates from my file, while certain fields take priority?
body: <p>So I have SQL that will add a code to a field if it detects duplicates. There is another field called DS</p>
  
  <p>DS can either be 'yes' or it can be 'no'</p>
  
  <p>How can I make it so if it finds a duplicate, 'yes' is not coded and 'no' is?</p>
  
  <p>Essentially 'yes' gets priority.</p>
  
  <p>My SQL:</p>
  
  <pre><code>WITH cte
       AS (SELECT *,
                  Row_Number() OVER(partition BY fips_county_code, last, suffix, first, birthdate Order by (select null)) AS Rn
           FROM   [PULLED REC])
  UPDATE cte
  SET    BAD_CODES = Isnull(BAD_CODES, '') + 'D'
  WHERE  RN &gt; 1; 
  </code></pre>