title: Find duplicate rows in SQL with column type having text
body: <p>I have a table with sturcture as below.</p>
  
  <pre><code>ID          bigint Primary key
  StudySysID  bigint Foreign key
  ContentText text    
  PageCount   int 
  StatusID    int 
  ...
  CreatedOn   datetime
  LastUpdated datetime    
  </code></pre>
  
  <p>I need to find duplicate <code>ContentText</code> with same <code>StudySysID</code>. If a <code>StudySysID</code> has more than one row with same <code>ContentText</code>, Select all rows with that <code>StudySysID</code> except the latest one (Last one can be identified by <code>CreatedOn</code> OR <code>ID</code>).</p>
  
  <p>I have tried this.</p>
  
  <pre><code>SELECT ID, StudySysID, CreatedOn, LastUpdated, StatusID, ContentText 
  FROM RP_TblStudyDetails  
  WHERE StudySysID IN (SELECT StudySysID
      FROM RP_TblStudyDetails  
      GROUP BY StudySysID
      HAVING COUNT(*) &gt; 1) 
  AND ID NOT IN (SELECT MAX(ID) AS ID
      FROM RP_TblStudyDetails  
      GROUP BY StudySysID
      HAVING COUNT(*) &gt; 1 )   
  ORDER BY StudySysID DESC, ID DESC
  </code></pre>
  
  <p>It selects all duplicates of a <code>StudySysID</code>, but some of them have different content text which I don't want to select. I don't know how to check duplicate <code>ContentText</code> along this.</p>