title: Remove Duplicate Values Without Distinct and Change Into NULL Values
body: <p>I want to remove duplicate rows and convert the duplicated ones into null values, but I don't know how to do it in SQL Server</p>
  <p>Here is my snippets of my table records</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>RefNo</th>
  <th>TrxDate</th>
  <th>TrxID</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1238688846</td>
  <td>2021-05-26 18:35:54.393</td>
  <td>'2f01b431-bca5-4d84-cd90-d5a8727a782d</td>
  </tr>
  <tr>
  <td>1238688846</td>
  <td>2021-05-26 18:33:48.993</td>
  <td>'2f01b431-bca5-4d84-cd90-d5a8727a782d</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>My expected result is change to NULL Values on row which is contain smallest date</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>RefNo</th>
  <th>TrxDate</th>
  <th>TrxID</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1238688846</td>
  <td>2021-05-26 18:35:54.393</td>
  <td>'2f01b431-bca5-4d84-cd90-d5a8727a782d</td>
  </tr>
  <tr>
  <td>NULL</td>
  <td>NULL</td>
  <td>NULL</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>Here is my code snippets</p>
  <pre><code>SELECT 
      X.ReferenceNo,
      X.TransactionDate,
      Y.TransactionID,
  FROM [TABLE] X
  INNER JOIN [TABLE] Y ON X.Key1  = X.Key1 
      AND RIGHT(Y.Key2,10) = RIGHT(X.Key2,10)
      AND Y.Key3 = 'Blablabla'
      AND X.Key4 &lt;&gt; Y.Key4
  </code></pre>
  <p>Your answer will be so helpful. Thank you</p>