0

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.

gclark18
  • 659
  • 6
  • 23

2 Answers2

0

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)

Peter206
  • 114
  • 1
  • 8
  • As this is a dbase file, is there any way to grab the last row written in the file? – gclark18 Jan 27 '23 at 11:18
  • Not with the regular database functions. If this function is needed a lot, then you could consider updating the database schema according to the requirements (your needs). – Peter206 Jan 27 '23 at 19:49
0

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.

Dale
  • 147
  • 7