• Daniel Matthee (8/2/2014)


    Can you please explain then when using an inner select statement (to minimize the sample )on huge table. (+- 20 columns, 400mil rows) the query runs WAY longer than actually putting the minimized sampel into and temp table and then reading from it.

    No, because there's nowhere near enough information (and we're hijacking the thread). If you want to discuss that, start a new thread, and read through my 'how to post performance problems' first to see exactly what's needed.

    That said, an 'inner select', more properly called a derived table, doesn't minimise the sample. Like a view, the derived table will be unrolled during parsing and exactly how the query is executed depends on the optimiser's choices.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass