How to get last record

Discussion of open issues, suggestions and bugs regarding IBDAC (InterBase Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
rcmz
Posts: 15
Joined: Wed 12 Mar 2008 05:58

How to get last record

Post by rcmz » Thu 29 May 2008 20:22

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

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Fri 30 May 2008 07:15

You can use a query like the following:

Code: Select all

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

rcmz
Posts: 15
Joined: Wed 12 Mar 2008 05:58

Post by rcmz » Fri 30 May 2008 14:12

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

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Mon 02 Jun 2008 06:56

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.

Post Reply