title: T-SQL SELECT TOP returns duplicates
body: <p>I'm using SQL Server 2008 R2.</p>
  
  <p>I'm not sure if I've discovered a strange SQL quirk, or (more likely) something in my code is causing this strange behaviour, particularly as Google has turned up nothing. I have a view called vwResponsible_Office_Address.</p>
  
  <pre><code>SELECT * FROM vwResponsible_Office_Address
  </code></pre>
  
  <p>..returns 403 rows</p>
  
  <p>This code:</p>
  
  <pre><code>SELECT  TOP 1000 *  FROM vwResponsible_Office_Address
  </code></pre>
  
  <p>..returns 409 rows, as it includes 6 duplicates.</p>
  
  <p>However this:</p>
  
  <pre><code>SELECT  TOP 1000 *  FROM vwResponsible_Office_Address
  ORDER BY ID
  </code></pre>
  
  <p>..returns 403 rows again.</p>
  
  <p>I can post the code for the view if it's relevant, but does it make sense for SELECT TOP to ever work in this way? I understand that SELECT TOP is free to return records in any order but don't understand why the number of records returned should vary.</p>
  
  <p>The view does use cross apply which might be affecting the result set some how?</p>
  
  <p>EDIT: View definition as requested</p>
  
  <pre><code>CREATE VIEW [dbo].[vwResponsible_Office_Address] 
  AS
      SELECT  fp.Entity_ID [Reg_Office_Entity_ID],
              fp.Entity_Name [Reg_Office_Entity_Name],
              addr.Address_ID
      FROM [dbo].[Entity_Relationship] er
      INNER JOIN [dbo].[Entity] fp
          ON er.[Related_Entity_ID] = fp.[Entity_ID]
      INNER JOIN [dbo].[Entity_Address] ea
          ON ea.[Entity_ID] = fp.[Entity_ID]
      CROSS APPLY (
          SELECT TOP 1 Address_ID 
          FROM [dbo].[vwEntity_Address] vea   
          WHERE [vea].[Entity_ID] = fp.Entity_ID  
          ORDER by ea.[Address_Type_ID] ASC, ea.[Address_ID] DESC
      ) addr
      WHERE [Entity_Relationship_Type_ID] = 25 -- fee payment relationship
  
      UNION
  
      SELECT  ets.[Entity_ID],
              ets.[Entity_Name],
              addr.[Address_ID]
      FROM  dbo.[vwEntity_Entitlement_Status] ets
      INNER JOIN dbo.[Entity_Address] ea
          ON ea.[Entity_ID] = ets.[Entity_ID]
      CROSS APPLY (
          SELECT TOP 1 [Address_ID]
          FROM  [dbo].[vwEntity_Address] vea
          WHERE vea.[Entity_ID] = ets.[Entity_ID]
          ORDER by ea.[Address_Type_ID] ASC, ea.[Address_ID] DESC
      ) addr
      WHERE ets.[Entitlement_Type_ID] = 40 -- registered office
      AND ets.[Entitlement_Status_ID] = 11 -- active
  </code></pre>