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

Select Statement 2

Status
Not open for further replies.

Ablecken

Programmer
Jun 5, 2001
130
US
All I want to do is select the last 5 records of a table. I know that this selects the first five:
SELECT TOP 5 <FIELDNAME> FROM <TABLENAME>
If I change the TOP to BOTTOM it gives me an error. Bottom is probably not correct. If anybody can help me I'll be very grateful.
Thanx
Able
 

SELECT TOP 5 <FIELDNAME> FROM <TABLENAME>
ORDER BY <FIELDNAME> DESC
Terry
------------------------------------
Blessed is the man who, having nothing to say, abstains from giving us worthy evidence of the fact. -George Eliot
 
try order by xxx dec John Fill
1c.bmp


ivfmd@mail.md
 
I tried that but it still only gives me the first 5. I need the LAST five. Thanks a lot guys.
Able
 

Which database program are you using? Terry
------------------------------------
Blessed is the man who, having nothing to say, abstains from giving us worthy evidence of the fact. -George Eliot
 
I am acutally writing an asp script. Using an Access db. (Don't laugh:)
Able
 
change order by, so as you to get from the last to first. In this case top will get the last records instead of first. John Fill
1c.bmp


ivfmd@mail.md
 

Please post your SQL statement. I just ran a query in Access 2000 and got the correct result. My query is

SELECT TOP 5 Employees.EmpID
FROM Employees
ORDER BY Employees.EmpID DESC;
Terry
------------------------------------
Blessed is the man who, having nothing to say, abstains from giving us worthy evidence of the fact. -George Eliot
 
Thanks a lot. It worked. I must have been typing it wrong before.
Able
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top