Quantcast
Channel: SQL Server Integration Services forum
Viewing all articles
Browse latest Browse all 24688

Query Execution- SQL Statments Order

$
0
0

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:

  1. FROM
  2. ON
  3. JOIN
  4. WHERE
  5. GROUP BY
  6. WITH CUBE or WITH ROLLUP
  7. HAVING
  8. SELECT
  9. DISTINCT
  10. ORDER BY
  11. 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/



Viewing all articles
Browse latest Browse all 24688

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>