title: Remove duplicate row and update next row to current row and continue
body: <p>I need  a select query ..</p>
  
  <p>Environment : SQL DBA -SQL SERVER 2005 or newer </p>
  
  <p>Example :<br>
  In this sample table, if I select top 20 no duplicate records should come and next record should be in 20 records .</p>
  
  <p>Example :</p>
  
  <p>123456 should  not repeat in 20 records and if 18th is duplicate, in place of 18th, 19th record should come and in 19th—20th should come, in 20th ---21st should come .</p>
  
  <p>No concern of Asc or Desc for rows .</p>
  
  <p>Lookup Table before</p>
  
  <pre><code>Id                                  Name 
  123456                              hello
  123456                              hello
  123654                              hi
  123655                              yes
  </code></pre>
  
  <p>LookUp Table after </p>
  
  <pre><code>Id                                  Name
  123456                              hello
  123654                              hi
  123655                              yes
  </code></pre>
  
  <p>My table:</p>
  
  <pre><code>CREATE TABLE [dbo].[test](  
  [Id] [int] IDENTITY(1,1) NOT NULL,
  [ContestId] [int] NOT NULL,
  [PrizeId] [int] NOT NULL,
  [ContestParticipantId] [int] NOT NULL,
  [SubsidiaryAnswer] [varchar](256) NOT NULL,
  [SubsidiaryDifference] [bigint] NOT NULL,
  [AttemptTime] [datetime] NOT NULL,
  [ParticipantName] [varchar](250) NOT NULL,
  [IsSubscribed] [bit] NOT NULL,
  [IsNewlyRegistered] [bit] NOT NULL,
  [IsWinner] [bit] NOT NULL,
  [IsWinnerConfirmed] [bit] NOT NULL,
  [IsWinnerExcluded] [bit] NOT NULL) ON [PRIMARY] 
  </code></pre>
  
  <p>My question is: from this select, we actually need the first 20, but unique ones. </p>
  
  <pre><code>SELECT TOP 20 * FROM test order by SubsidiaryDifference 
  </code></pre>
  
  <p>When we do the above query, we have currently some double in there. In case there is a double, we need take them only 1 time and take the next one</p>
  
  <p>Any one know this issue ?</p>
  
  <p>Thanks in advance :)</p>