• Hugo Kornelis (9/19/2012)


    Nice question. I almost got it wrong, because I had first overlooked the TOP clause.

    However, the official correct answer is still a bit questionable. The result of a TOP without ORDER BY is officially undocumented and undefined...

    Hello Hugo,

    (bit confused) Just trying to understand... "the official correct answer" with respect to the behavior of the TOP with TABLESAMPLE ? or the output (which have to be consistent) of the query?

    The Person.Person table contains 19,972 rows.

    The following statement returns approximately 10 percent of the rows.

    The number of rows returned usually changes every time that the statement is executed.

    As the BOL states that the output usually changes, so to my understanding the TOP will work upon the resultset of the TABLESAMPLE returns just to limit the top 'n' rows to display on the final output as it uses the primary key constraint so ORDER BY might not be considered here?

    Thank you for your contribution (there is stuff always to learn):-)

    ww; Raghu
    --
    The first and the hardest SQL statement I have wrote- "select * from customers" - and I was happy and felt smart.