Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 query help

Author  Topic 

sunsanvin
Master Smack Fu Yak Hacker

1274 Posts

Posted - 2006-10-09 : 04:10:59
hi friends,
i need a query to display the rows from 2 to 5 records.

suppose i have 100 records in my table.

i need records from 2 to 5 only.

thanks in advance

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-10-09 : 04:19:59
How do you determine row/record order?


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2006-10-09 : 04:36:12
Refer this article, point # 13:

[url]http://weblogs.sqlteam.com/mladenp/archive/2005/08/01/7421.aspx[/url]

Harsh Athalye
India.
"Nothing is Impossible"
Go to Top of Page

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2006-10-09 : 05:47:52
If you have primary key in your table, then have a look at the following script


SELECT (SELECT COUNT(i.au_id)
FROM pubs..authors i
WHERE i.au_id >= o.au_id ) AS RowID,
au_fname + ' ' + au_lname AS 'Author name'
FROM pubs..authors o
ORDER BY RowID


This will generate the RowId and then accordingly you can select the rows which you want sepcifying the range in the where clause.

if you are using SQL Server 2005 then have a look at following link.
http://www.sqlservercentral.com/columnists/mcoles/sequentialordering.asp


Chirag

http://chirikworld.blogspot.com/
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-10-09 : 09:35:44
Do you need Pagination?

http://weblogs.sqlteam.com/jeffs/archive/2003/12/22/672.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2006-10-09 : 09:58:33
The physical order of data in a database has no meaning

What purpose does it serve you to say you want rows 2 thru 5?

Tell us what value rows 2 thru 5 have, then we can help



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page
   

- Advertisement -