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

Query

Status
Not open for further replies.

sha123

Programmer
Nov 13, 2002
58
ZA
Is there a way of creating a delete query that delete all the entries in a table except the last record?
 
Can you give us some details like the table's structure along with some test data?
 
You would need an autonumber field or a "last updated" field in the table.

Your delete would be like:

Delete * from YourTable
Where Field <> (Select Max(Field) from YourTable) ;
 
JonFer,

sha123 wants to delete everything but the LAST record
 
Assuming [Field] has the highest value on the last record (like for an incremental autonumber or a &quot;last updated&quot; date), the delete will work. I don't like using the &quot;Last&quot; aggregate function because it is dependent on the record sort which you don't always know.
 
I probably misunderstood the 'last', thinking 1st record, 2nd record ... last record and not the last inserted record. I personaly agree with you about the
Code:
last
function.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top