I'm having a bit of trouble understanding the TOP clause in an insert statement. On several MS sites it appears to state that if the TOP(n) clause is used, it will select a "random" set specified by "n" [MS Site][1]. However, that does not appear to be the case. Instead, this query returns an ordered recordset by ID: TRUNCATE TABLE #t
**insert top (5)**
into #t
output
inserted.ID, inserted.facilityNo, inserted.portNo, inserted.endcode, inserted.cable
select *
from dbo.temp_data
The above result contrasts with the query below which actually returns a random ordered recordset: TRUNCATE TABLE #t
insert into #t
output
inserted.ID, inserted.facilityNo, inserted.portNo, inserted.endcode, inserted.cable
**select top (5)** *
from dbo.temp_data
order by NEWID() What's the deal with this? Why include the TOP(n) clause as an option for the INSERT, when I could just use it within the select statement for either ordered or random? [1]:
http://msdn.microsoft.com/en-us/library/ms189463.aspx