select the last row in a dbase dbf file with no primary key/id column

118 Views Asked by At

Given the following file (that I have no control over):

enter image description here

I want to be able to select the last row. I tried doing an ORDER BY the date column; however, as you can see there may be multiple date columns.

Without an ID field, how can I select the last column that physically exists in the file?

I've spent a while googling everything points to sorting by a column.

2

There are 2 best solutions below

2
Peter206 On

As you have no clustered index (which would constitute the physical ordering of the data), it is impossible. Tables are only ordered deterministically if you use an order by clause.

See e.g. sql-best-practice-to-deal-with-default-sort-order

If your current concern could still be considered in the database schema design, the adding of a loaddate field can be considered, which would be set to the time the row is created. (If your last column is such a loaddate you could still use an order by clause on the column)

0
Dale On

It has been awhile, but as I recall you could:

use filename go bottom skip -1

This should take you to the last physical record in the table. It will not work if you have a structural index (index file with the same name as the table), I think.

The above code sample should be 3 lines, I don't know why this is appearing as 1 line.