Click here to Skip to main content
15,904,822 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi,

I have 100 records from my table. I want only between 91 to 80 records.

Every time I will get last but 10 records. I mean next time 200 records in my table I want records between 191 to 180. like this.

please help me,

Thank you.
Posted
Updated 27-May-14 18:35pm
v2

Hi...
See this one!
SQL
>>for last records from table only.
SELECT *
FROM table_name
ORDER BY id DESC
LIMIT 1

>>for between records from table only.
SELECT * FROM test LIMIT 10, 100
//It will display records from 101-110

Thank u.
 
Share this answer
 
v2
try this.. :)

SQL
with samp as(

  select *,ROW_NUMBER() over (order by id)AS RowNo from tableName
  )
  select * from samp where RowNo >((select max(RowNo) from samp)-21) and  RowNo <((select max(RowNo) from samp)-8)
 
Share this answer
 
SQL
declare @maxRowIndex int

set @maxRowIndex =(  select top 1 ROW_NUMBER() OVER (ORDER BY JobID desc) AS RowNum
     FROM Job order by RowNum desc)
  select @maxRowIndex


SELECT *
FROM (
     SELECT *, ROW_NUMBER() OVER (ORDER BY JobID desc) AS RowNum
     FROM Job
     ) AS MyDerivedTable
     where MyDerivedTable.RowNum<=(@maxRowIndex-9) and MyDerivedTable.RowNum>=(@maxRowIndex-20)
 order by JobID asc
 
Share this answer
 
Try this:

SQL
SELECT *FROM tbl_name
ORDER BY id DESC OFFSET 10 ROWS FETCH NEXT 10 ROWS ONLY;



Refer this :
http://technet.microsoft.com/en-us/library/gg699618%28v=sql.110%29.aspx[^]
 
Share this answer
 
Comments
NagaRaju Pesarlanka 28-May-14 0:55am    
I got this error.
Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'ORDER'.
Msg 153, Level 15, State 2, Line 1
Invalid usage of the option NEXT in the FETCH statement.
King Fisher 28-May-14 1:11am    
Version of Sql Server?
NagaRaju Pesarlanka 28-May-14 1:12am    
sql server 2012
Microsoft SQL Server Management Studio 11.0.2100.60
Microsoft Analysis Services Client Tools 11.0.2100.60
Microsoft Data Access Components (MDAC) 6.1.7601.17514
Microsoft MSXML 3.0 5.0 6.0
Microsoft Internet Explorer 9.11.9600.16521
Microsoft .NET Framework 4.0.30319.1022
Operating System 6.1.7601
King Fisher 31-May-14 0:19am    
check with that link .it will work
Nirav Prabtani 28-May-14 1:07am    
my 5+
Modify the below query to suit your requirement


SQL
SELECT * FROM
    (SELECT ROW_NUMBER()
        OVER (ORDER BY Your_Order_Column) AS Row,
       Col1, Col2 
    FROM TableName) AS T1
WHERE Row > 80
 
Share this answer
 
select top 10 * from Job order by jobid desc 
 
Share this answer
 
Try below query

SQL
declare @startvalue int=91;
declare @endvalue int=80;
select top (@startvalue) * from tblFiles
except
select top (@endvalue) * from tblFiles
 
Share this answer
 
This Might Help You..
..
SELECT * FROM table WHERE date = (SELECT MAX(date) FROM table) LIMIT 1;

..
Thanks
 
Share this answer
 
you can fetch last 10 by fetching the top 10 records as follows..


Updated..

SQL
select top 10 * from (select top 20 * from [table ] order by column1 desc) as a order by column1 asc


XML
<pre lang="SQL">

select top 10 * from tblName order by col1 desc


here col1 is the table colum by which you ordering your table.
</pre>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900