0
I am currently creating a Java/Mysql Desktop program. When inserting into the bank, the table is very simple:
id - dataInserido - códigoProduto - qtd
I would like, through an SQL, to group in descending order the last records entered on the same date. Example: I have atabela of inserted products
id - data - produto - qtd
1 - 20/05/2017 - 10001 - 100
1 - 24/05/2017 - 10002 - 10
1 - 27/05/2017 - 100010 - 30
1 - 29/05/2017 - 100020 - 60
1 - 29/05/2017 - 100060 - 70
1 - 29/05/2017 - 100010 - 100
How to group the last ones (05/29/2017), being 100020, 100060 and 100010, since I have to mount this table in Java ? A kind of filter requested by the user.
ps: I don’t want to take any date by java, but rather a query by sql itself.
Puts an example of the output you want
– Sorack
If I understand your question (because I’m not so good at Java yet), I always do this: while (rs.next()) { List.add(new Object[]{rs.getInt("id")}); } I still haven’t defined how the output and how I’m going to get the values in Java. If you can also suggest something, thank you. This challenge has now appeared since I started
– rafB
A simple
SELECT * FROM tabela ORDER BY dataInserido DESC
would not solve?– Max Rogério
Not much. The bank would pick up all the records and order. I would like only the last date of the registered products.
– rafB
Or if you wanted to bring the records only on the present day:
SELECT * FROM tabela WHERE dataInserido = CURDATE()
– Max Rogério
Thanks. Your suggestion for the "Launched Today" filter I’m doing will be helpful too.
– rafB