POSTING UNDER INTEGRATION SERVICES HOPING EXPERT HERE COULD HELP ME EXPLAIN THIS SCENARIO
I would ask a simple question which has amazed me today, i have read and was pretty sure on the QUery execution sequence for SQL statments is as below:
- FROM
- ON
- JOIN
- WHERE
- GROUP BY
- WITH CUBE or WITH ROLLUP
- HAVING
- SELECT
- DISTINCT
- ORDER BY
- TOP
The intresting thing for me today was the TOP clause, i had always though say for a query:
Query 1: select top 10 * from TABLE order by COL1 vs Query 2:select * from TABLE order by COL1
I expected both the queries to take same time, as TOP would be applied only when whole resultset is obtained and sorted, however the Query 2 was within seconds and Qury 1 was running for 10 mins.
Could someone share there thougts on this?
Adding Queries using AdventureWorks
select top 10 SafetyStockLevel,* from dimproduct
order by dimproduct.SafetyStockLevel
select SafetyStockLevel,* from dimproduct
order by dimproduct.SafetyStockLevel
Abhinav
http://bishtabhinav.wordpress.com/