May 11, 2005 at 7:41 am
...or to put it Remi's way
Select
id
, name
from dbo.SysObjects O1
where (Select count(*) from dbo.SysObjects O2 where O2.id <= O1.id) % 4 = 0 order by id
--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/[/url]
May 11, 2005 at 7:49 am
Frank - make way for the next MVP
**ASCII stupid question, get a stupid ANSI !!!**
May 11, 2005 at 7:55 am
Awesome, I am working on few millions of records and it really works great, Thanks to Frank and Remi for your great input and help.
Prasad Bhogadi
www.inforaise.com
May 11, 2005 at 7:58 am
Hey Frank I'll have to tatoo those D@mn unequal joins someday because I never think about using them... Fortunately for me, this time the subquery runs about 3 times faster than the unequal join .
May 11, 2005 at 7:59 am
How long does it take to run that query a a few M rows?
May 11, 2005 at 8:06 am
It is taking about 8 seconds but I have few more joins and a clustered index on my table on the ID column and this is on my Sandbox not on the Staging yet.
Thanks
Prasad Bhogadi
www.inforaise.com
May 11, 2005 at 8:08 am
Hey, I didn't say it's efficient The first suggestion is ANSI SQL, I think ...
But a quick look at the execution plans reveals that both are pretty similar, unless I haven't missed a thing.
I don't know what it's gonna be on a 1 million row table. And I don't want to try. In this case I would opt for the temp table method.
--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/[/url]
May 11, 2005 at 8:08 am
Wow... must be some kick ass server you got there.
Thanx for the timing.
May 11, 2005 at 8:08 am
I tried this on one of our tables with about 7000 rows - running on a VERRRRRRY SLOW network - when the index wasn't clustered it took 22 seconds - when I clustered it, it took 11 seconds - will be interesting to see Prasad's response...
**ASCII stupid question, get a stupid ANSI !!!**
May 11, 2005 at 8:19 am
Well this is for data analytics sampling that I am using this query and I will be picking every 'x' (4th in the question I asked) record in the total number of filtered records that are fetched from a different procedure and the total output of the stored procedure in my context is about 15k records and they are written to a CSV file.
Thanks
Prasad Bhogadi
www.inforaise.com
May 11, 2005 at 8:26 am
If this is random sampling I would rather use ORDER BY NEWID() than ORDER BY [date], as you've mentioned in your first posting in this thread.
Just my $0.02
--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/[/url]
May 11, 2005 at 8:38 am
Ya Select top 25 PERCENT * from dbo.YourTable order by Newid()... Would be even faster than everything else we suggested. Th eonly problem is that the 25% couldn't easily be dynamic if need be...
May 11, 2005 at 8:53 am
Well its not random picking, I need to pick every 'x' row like 1,5,9,13 so on so forth, the interval is derived basically on the total count of records that satisfy a filter algorithm for a selected date range.
Thanks.
Prasad Bhogadi
www.inforaise.com
May 11, 2005 at 11:20 am
k.. then you're on your way... Good luck with this project.
Viewing 14 posts - 16 through 29 (of 29 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy