I am currently writing a Java program.
Brief description of the component:
I have an "Entries" table. This table has the following columns: Date (which is entered automatically when the user makes a double entry) Input (This is the double number from the user)
With 5 entries, for example, the program should now access the last 2 entries made by the user and reflect them in the program.
For example, the table looks like this:
Date --------- Entry
21.01.2022 -- 500
01.03.2022 -- 551
04.05.2022 -- 629
30.06.2022 -- 701
15.07.2022 -- 781
Then the program should give me the 701 and the 781.
What is the most sensible way to do this? It makes no sense to use the following "SQL statement": Select where date 06/30/2022 because it is no longer useful when the user makes a new entry.
Please help!!
CodePudding user response:
You can use the following SQL statement to select the last two rows:
select * from Entries order by date desc limit 2;
CodePudding user response:
select Entry
from your_table
order by date desc -- show most recent entries above in the results
fetch first 2 rows only; -- show first 2 records only