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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RowNum and Order by 2

Status
Not open for further replies.

NuniPR

Programmer
Mar 3, 2005
55
PR
Hi Guys!

I have a table that has 47,000,000 records. I need to get the first 1,000 rows in descending last_modified_date order.

I get as far as this:
Code:
select rownum, location_id, last_modified_userid, 
last_modified_date from location 
where rownum <= 1000 
order by last_modified_date desc

When I do this, what I get is the first 1,000 rows ordered. Does any of you guys have the correct syntax to get the table sorted and those first 1,000 records of the new order?

Thanks a bunch, guys!


Nunina [gorgeous]
IT Manager
San Juan, PR
 

Try this:
Code:
SELECT *
  FROM (SELECT location_id, last_modified_userid, last_modified_date,
               ROW_NUMBER () OVER (ORDER BY last_modified_date DESC) rn
          FROM LOCATION)
 WHERE rn <= 1000;
[3eyes]


----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top