db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John English <john.fore...@gmail.com>
Subject Re: Retrieving newest record from derby table
Date Mon, 21 Oct 2013 11:27:18 GMT
On 21/10/2013 05:01, Bob M wrote:
> Hi again
>
>> b) retrieve the last record
> ***************************
> Assuming you have a column x which imposes the order you're after:
>
> SELECT MAX(x) FROM t
>
> to get the max key
>
> SELECT * FROM t WHERE x=<max key>
> **************************
> I have a primary key comprising first two columns Date and Hours e.g.
> 01-01-2009, 6
>
> And so what do I change the above code suggestion to ?

You can always order the results and select one row:
    SELECT * FROM t ORDER BY datecol DESC, hourcol DESC FETCH FIRST ROW ONLY

Sounds like you need to read a good book on SQL and also a tutorial on JDBC.
-- 
John English

Mime
View raw message