select between n-4 and n-20

Results 1 to 3 of 3

Thread: select between n-4 and n-20

  1. #1
    Join Date
    Dec 1969

    Default select between n-4 and n-20

    Hi,<BR><BR>i&#039;m using sql server 2000 and wish to select the last N records in a table.<BR><BR>However I need to cut off the 1st n records as these are shown in a separate list with additional info. i.e.<BR><BR>List 1<BR><BR>Record 24<BR>details details details<BR><BR>Record 23<BR>details details details<BR><BR>Record 22<BR>details details details<BR><BR>List 2<BR><BR>Record 21<BR>Record 20<BR>Record 19<BR>Record 18<BR>.<BR>.<BR>.<BR>Record 1<BR><BR><BR>List 1&#039;s easy enough: SELECT TOP 3 * ORDER BY id DESC<BR><BR>I&#039;m stuck on how to then create a scond recordset starting from Nth from last record...<BR><BR>Can anyone please help??<BR><BR>Kes<BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: select between n-4 and n-20

    n = 4<BR>x = 20<BR><BR>Select top x - n * FROM &#060;table&#062; where id Not in <BR>(Select top n -1 id FROM &#060;table&#062;)<BR><BR>OR<BR><BR>Select * FROM &#060;table&#062; Where ID in (SELECT Top N ID FROM &#060;table&#062; OREDER BY ID ASC) ORDER BY ID DESC

  3. #3
    Join Date
    Dec 1969

    Default WK's answer works but...

    ...why do this via SQL???<BR><BR>If you are working in ASP, wouldn&#039;t it be simpler to just use VBS to show the first N in one list/table and the rest in another????<BR><BR>Only one DB query, then.<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts