justone
20th February 2003, 15:57
I'd like to read data from baan table with SQL statement. The problem is that this table is date oriented (it's a table of currencies values) and I have to find the last change of currency value for recalculation from local currency to EUR (it is very close to the end of table). Is it possible to search through table from the bottom (i meant to go to the last record with db.last() and then search backwards). The problem is I don't know how to create SELECT statement to start from the back.

Thanks for help in advance

manusatsangi
20th February 2003, 16:07
To start the selection of SQL query from the last record to first record onwards can be done by:


select ttmmmxxx.*
from ttmmmxxx
where ..........
order by ttmmmxxx._index1 desc


This will sort the table in descending order of your primary index
Make sure that you select all the fields constituting the primary key. In the example I have selected all (*).

Regards
Manu

RobertB
20th February 2003, 16:08
Hi,

Use select ....
from....
where...
order by some.date.field descThis will list the table in reverse order (descending order), and you can pick the first one as the latest one

Another way would beselect ....
from....
where some.date.field = (select max(some.date.field)
from...
as set with 1 rows)
order by...HTH