So if I'm correct your tables look like this?
Code:
Table 1 table 2
r_id r_c_id r_e_date ra_id Rec_id ra_e_date
10 1 01/09/2006 10 03 01/09/2006 <Record 1
09 2 01/09/2006 09 02 01/09/2006
08 2 01/08/2006 08 02 01/08/2006
07 1 01/08/2006 07 01 01/08/2006 <Record 2
And tab1.r_id = tab2.ra_id is always true? And tab2.Rec_id is a representation of tab1.r_c_id? Which record would you have returned, 1 or 2?
I"m sorry but I've been reading your remarks over and over again and still don't know what exactly you're looking for. Is it the second newest record in a table given a certain column condition? With this query you can select the (fysically) last (newest) but one record in table 1 with the same r_c_id:
Code:
SELECT * FROM table_1 a
WHERE rowid = (SELECT max(rowid)
FROM table_1 b
WHERE b.r_c_id = a.r_c_id
AND rowid < (SELECT max(rowid)
FROM table_1 c
WHERE c.r_c_id = b.r_c_id))
which in case of the Table 1 example above would return r_id: '07' (Record 2, if r_e_date is the date of insertion). And if there's only one row for the r_c_id it returns none.
Rowid is an implicit column that marks the relative position of a row within a table; if no ORDER BY clause is specified the results of a query are ordered by rowid. As it gets an unique successive number with every insert it marks the sequence in which rows were inserted. (But somehow I've got the feeling this is not what you're looking for...)
Regards