I have a table (Oracle):
price
--------
integer id (pk)
integer part_id (fk)
number amount
timestamp change_timestamp
And whenever a part price is changed the software (not mine) adds a new row to this table. Instead of altering the data and there being one entry per part, it adds a new row to the table. The software then looks for the latest entry. But the "old" data lingers in the table.
I am trying to write a query that gives me a) the current (latest) price and b) the date that price was entered.
I wrote this query:
select part_id, amount, max(change_timestamp)
from price
group by part_id, amount
But this returns every entry for that part, even the old ones.
How do I return the latest date and the amount for that date while discarding the older, irrelevant data?
No, it's not my database to change or my software to change.