Obtain data with the lowest sequence number

1

I'm IN ORACLE SQL I do not know how to make the next query, to see if you can help me. I have the following table, in which there are 2 different products, inserted in different dates and times, and with different quantities:

Producto1 1/12/17 15:30 5u
Producto1 5/12/17 16:00 3u
Producto1 5/12/17 12:12 1u
Producto2 1/12/17 15:05 8u
Producto2 6/12/17 11:45 7u

And I want you to return the record with the most recent date and time of each product, but do not repeat the product. So:

Producto1 5/12/17 16:00 3u
Producto2 6/12/17 11:45 7u

How do I do it? Thanks in advance!

    
asked by juan medina 03.08.2018 в 00:39
source

1 answer

1

Try the following, it is not the best of the queries but it achieves the goal:

select pp.* from tabla_productos pp 
join (select producto, max(fecha) fecha from tabla_productos group by producto) p
on p.producto = pp.producto and p.fecha = pp.fecha

You can work on it and improve it, I hope it works for you!

    
answered by 03.08.2018 в 23:18