Page 1 of 1

How to get last record

Posted: Thu 29 May 2008 20:22
by rcmz
Hello

I have a table in a FB database that holds all the invoices of a Client and I would like to get the last invoice of any client.

At this moment I select * from invoices where client = noclient order by date
and then go to Last

Is ther a way to get only the last record so that this process be a lot faster.

TIA
Ramiro

Posted: Fri 30 May 2008 07:15
by Plash
You can use a query like the following:

Code: Select all

select * from invoices where client = noclient
order by date desc
rows 1

Posted: Fri 30 May 2008 14:12
by rcmz
Hi,

thank you for your fast reply :D

I tried your suggestion but if the client haves 2 or more invoices on the same day it fetches the first in that day and not exactly the last one. :(

I also have an ID column on that table.

TIA
Ramiro

Posted: Mon 02 Jun 2008 06:56
by Plash
You should modify your table to have a column of TIMESTAMP type. In this case you can find a record with the largest value in this column.