Delete record

  • Thread starter Thread starter Todd Huttenstine
  • Start date Start date
T

Todd Huttenstine

Hey guys

How do you delete the last record in a table using SQL?


Thank you'
Todd Huttenstine
 
What is the last record? How do you know it is the last record? Is there a
datetime field that tells you it is the last record? Or some sequential number?

Records do not have an order in a table. They may appear to consistently have
an order, but ....

Let's say you have a date time field that is UNIQUE to each record. Then you
could do

DELETE T.*
FROM Table As T
WHERE T.DateTimeField =
(SELECT Max(T1.DateTimeField)
FROM Table as T1)

That should delete the record(s) with the latest date time in the field. If you
have a sequential field then you can use that in the same manner.
 
Back
Top