Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem getting n last items

Status
Not open for further replies.

abelgv

Programmer
Mar 29, 2002
4
ES
hi,

i'm working with sql server 7 and i have a table like this:

---------------------
id date section

1 1/1/2001 2
2 2/2/2002 3
etcetera
---------------------

I need to get the 5 last items from every section, "last items" means order by date desc... I cannot find the sql expression... "5 last items from every section" means
that the sql should return 15 rows if i have 3 sections,
supossing there are 5 items available for every section.

Thanks for any help.
Abel
---------------------------
 
Try this: (untested)

select *
from YourTable u1
where Date in (select TOP 3 Date from YourTable u2
where u2.Section=u1.Section
order by Date desc)
Order by Section, date desc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top