473,379 Members | 1,278 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Select every Nth row from a table

Hi all,

please help me in writing a query for selecting every Nth row in a table.

Thank you in advance
Mar 13 '08 #1
5 8794
amitpatel66
2,367 Expert 2GB
Hi all,

please help me in writing a query for selecting every Nth row in a table.

Thank you in advance
Could you please post your table structure here and what you have tried so far?
Mar 13 '08 #2
deepuv04
227 Expert 100+
Could you please post your table structure here and what you have tried so far?
Hi,
try the following query to get nth record
Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT * From (SELECT  *,(Dense_Rank() Over (Order By Column_Name Desc)) As Rank 
  3. From Table_Name) As Z Where Rank=3
  4.  
  5.  
Mar 14 '08 #3
Hello deepuv04

Thank you for the reply. But this query gives only the nth record in table, but I want every Nth row (ex: 10th, 20th, 30th....) in the table. Can we do that?
Mar 14 '08 #4
deepuv04
227 Expert 100+
Hello deepuv04

Thank you for the reply. But this query gives only the nth record in table, but I want every Nth row (ex: 10th, 20th, 30th....) in the table. Can we do that?
hi,
we can do that. pass the ranks as varchar comma seperated

eg: @Rank as '10,20,30'

use the following query, it will give you the ranks you specified, if @Rank is null the will give you all the records

Expand|Select|Wrap|Line Numbers
  1.       SELECT * FROM (SELECT  *,(Dense_Rank() Over (ORDER BY Column_Name DESC)) AS Rank
  2.       FROM Table_Name) AS Z 
  3.       WHERE     (','+isnull(@Rank,convert(varchar(10),Z.Rank)  )+',') like 
  4.              ('%,'+convert(varchar(20),Z.Rank)+ ',%')))
  5.  
  6.  
Mar 17 '08 #5
Thank you ..I will try this..
Mar 17 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

23
by: ian justice | last post by:
Before i post actual code, as i need a speedyish reply. Can i first ask if anyone knows off the top of their head, if there is a likely obvious cause to the following problem. For the moment i've...
0
by: Miroslav I. | last post by:
------=_NextPart_000_0009_01C35A6F.9908B420 Content-Type: text/plain; charset="iso-8859-2" Content-Transfer-Encoding: quoted-printable Hallo suppose you have a table with great number of...
4
by: Denis St-Michel | last post by:
Hello All, Hope some Guru will be able to help me with this. Let's take this example table A ------------------------------------------------------------------------------- id | ...
1
by: Gerald Maher | last post by:
Hi I need to select 2 tables . The field 'p_description' is not always aviable but i still need to print it to the screen SELECT * FROM task,p_description WHERE ComponentIDLink = 34 OR...
3
by: Ian T | last post by:
Hi, I've got what I think (probably incorrectly) should be a simple SELECT : Two colums with data like col1 col2 1 50 1 51 2 50
6
by: BlueDragon | last post by:
Grrr! I'm trying to run a script: print 'Declaring cursor' declare cInv cursor forward_only static for select distinct inv.company, inv.contact, inv.address1, inv.city,
4
by: jimh | last post by:
I'm not a SQL expert. I want to be able to write a stored procedure that will return 'people who bought this product also bought this...'. I have a user table that links to a transaction table...
7
by: CharlesEF | last post by:
Hi All, I have run into another problem that is eating my lunch. Should be simple but I am having one heck of a time. Please look at this SELECT statement: SELECT FROM States WHERE ] =...
4
by: Alex | last post by:
Hi, I have a bit string , 7 bits, every bit representing a day of the week. e.g. 1110011. Is there and easy way where I can translate/format that string in a query. I want to give the string...
13
by: James Conrad St.John Foreman | last post by:
One of the larger tables in our database is now 6.8 million rows (1 per financial transaction since 2000). Every time an amendment is made to a booking, new rows are added to the table for each...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.