Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2008
»
SQL Server 2008 - General
»
how top clause works
how top clause works
Rate Topic
Display Mode
Topic Options
Author
Message
sej2008
sej2008
Posted Tuesday, January 15, 2013 12:56 AM
SSC Journeyman
Group: General Forum Members
Last Login: Friday, May 10, 2013 1:00 AM
Points: 76,
Visits: 120
I found that TOP clause works little randomly with
Select TOP 50 percent * from Tablename as it is not giving exact 50 percent in my result set .how it gets the data reading from data pages.I have Idea that it is little random in working in respect to percent clause over datapages.
Post #1407060
e4d4
e4d4
Posted Tuesday, January 15, 2013 1:02 AM
SSC-Enthusiastic
Group: General Forum Members
Last Login: Today @ 10:16 AM
Points: 151,
Visits: 1,033
http://msdn.microsoft.com/en-us/library/ms189463.aspx
" PERCENT
Indicates that the query returns only the first expression percent of rows from the result set. Fractional values are rounded up to the next integer value.
"
Post #1407062
ChrisM@Work
ChrisM@Work
Posted Tuesday, January 15, 2013 1:24 AM
SSCertifiable
Group: General Forum Members
Last Login: Today @ 9:32 AM
Points: 5,613,
Visits: 10,981
sej2008 (1/15/2013)
I found that TOP clause works little randomly with
Select TOP 50 percent * from Tablename as it is not giving exact 50 percent in my result set .how it gets the data reading from data pages.I have Idea that it is little random in working in respect to percent clause over datapages.
What happens when you add ORDER BY to your query?
“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.”
- Gail Shaw
For fast, accurate and documented assistance in answering your questions, please read
this article
.
Understanding and using APPLY, (I)
and
(II)
Paul White
Hidden RBAR: Triangular Joins
/
The "Numbers" or "Tally" Table: What it is and how it replaces a loop
Jeff Moden
Exploring Recursive CTEs by Example
Dwain Camps
Post #1407071
Bhuvnesh
Bhuvnesh
Posted Tuesday, January 15, 2013 3:55 AM
SSCrazy
Group: General Forum Members
Last Login: Tuesday, March 26, 2013 8:41 AM
Points: 2,562,
Visits: 3,451
sej2008 (1/15/2013)
I found that TOP clause works little randomly with
Select TOP 50 percent * from Tablename as it is not giving exact 50 percent in my result set .how it gets the data reading from data pages.I have Idea that it is little random in working in respect to percent clause over datapages.
sql server never gives guarantee about the order of data until/unless ORDER BY clause is mentioned. see
http://msdn.microsoft.com/en-us/library/ms188385.aspx
-------Bhuvnesh----------
While 1 = 1 (Learning SQL....)
Click to get fast response of your post
Post #1407145
Grant Fritchey
Grant Fritchey
Posted Tuesday, January 15, 2013 4:26 AM
SSChampion
Group: General Forum Members
Last Login: Today @ 3:40 PM
Points: 13,380,
Visits: 25,164
Yes, it's going to be a little bit random in the number of rows it returns. However, for a given set of inputs against a constant set of data, you should see consistent results. But as soon as the data changes or the inputs change, all bets are off.
----------------------------------------------------
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood..." Theodore Roosevelt
The Scary DBA
Author of:
SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans
Product Evangelist for
Red Gate Software
Post #1407155
Bhuvnesh
Bhuvnesh
Posted Tuesday, January 15, 2013 5:08 AM
SSCrazy
Group: General Forum Members
Last Login: Tuesday, March 26, 2013 8:41 AM
Points: 2,562,
Visits: 3,451
Grant Fritchey (1/15/2013)
as soon as the data changes or the inputs change, all bets are off.
yes i have also realized that for smaller set , we can see the consistent data more often but what make it unexpected or randomly ordered for larger set (
for the time being, we can keep out parallelism,out of site here
) ?
-------Bhuvnesh----------
While 1 = 1 (Learning SQL....)
Click to get fast response of your post
Post #1407185
Grant Fritchey
Grant Fritchey
Posted Tuesday, January 15, 2013 5:12 AM
SSChampion
Group: General Forum Members
Last Login: Today @ 3:40 PM
Points: 13,380,
Visits: 25,164
Bhuvnesh (1/15/2013)
Grant Fritchey (1/15/2013)
as soon as the data changes or the inputs change, all bets are off.
yes i have also realized that for smaller set , we can see the consistent data more often but what make it unexpected or randomly ordered for larger set (
for the time being, we can keep out parallelism,out of site here
) ?
Random ordering will absolutely not occur unless you are not using an ORDER BY statement. Then, it's all over Microsoft documentation and the web, there's no guarantee for data order without an ORDER BY statement. It's that simple. Any number of things can affect the order of the data returned, page splits and rearrange, different execution plans based on changing statistics or changing parameters, more. If you don't use an ORDER BY, you can't be surprised when the order is different from one time to the next.
----------------------------------------------------
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood..." Theodore Roosevelt
The Scary DBA
Author of:
SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans
Product Evangelist for
Red Gate Software
Post #1407188
Bhuvnesh
Bhuvnesh
Posted Tuesday, January 15, 2013 10:04 PM
SSCrazy
Group: General Forum Members
Last Login: Tuesday, March 26, 2013 8:41 AM
Points: 2,562,
Visits: 3,451
thanks grant
-------Bhuvnesh----------
While 1 = 1 (Learning SQL....)
Click to get fast response of your post
Post #1407585
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.