This is what triggers are for, I'm also going to talk about DATE_SUB and date intervals
Using triggers will allow you to keep the current price in the price table and keep historical prices in a separate table.
For instance, consider creating a new table called price_table_old
price_table_old:
price_id int
item_id int
price_amount float
change_date date
On the price_table, create an 'update' trigger...
insert into price_table_old ( `item_id`, `price_amount` , `change_date ` )
VALUES ( OLD.`item_id` , OLD.`price_amount` , NOW() )
To help you with trigger syntax, I copied the trigger I used for a staff table below
When ever someone changes a price, the price_table_old table is automatically updated.
From here, things are a little more logical to get the current price and comparisons of previous prices.
You could run a query like....
SELECT
price_table.item_id ,
price_table.price_amount ,
(price_table.price_amount - price_table_old.price_amount ) AS pricediff ,
price_table_old.change_date
FROM
price_table
LEFT JOIN
price_table_old ON price_table_old.item_id = price_table.item_id
ORDER BY price_table.item_id , price_table_old.change_date DESC
or stick a where in there to zone in on a specific item and/or date range and/or a limit to get the last (say) 3 price changes.
For instance, to get a list of price changes for the last 3 days on all items, you could use a statement like this
SELECT
price_table.item_id ,
price_table.price_amount ,
(price_table.price_amount - price_table_old.price_amount ) AS pricediff ,
price_table_old.change_date
FROM
price_table
LEFT JOIN
price_table_old ON price_table_old.item_id = price_table.item_id
WHERE
price_table_old.change_date > ( DATE_SUB( NOW() , INTERVAL 3 DAY ))
ORDER BY price_table.item_id , price_table_old.change_date DESC
Here is my staff table trigger...
CREATE TRIGGER `Staff-CopyOnUpdate` BEFORE UPDATE ON `staff`
FOR EACH ROW insert into staff_old
( `sid` , `title`, `firstname` , `surname` , `type`,
`email` , `notify`, `actiondate`, `action` )
VALUES
( OLD.`sid` , OLD.`title`, OLD.`firstname` , OLD.`surname` , OLD.`type`,
OLD.`email` , OLD.`notify`, NOW() , 'updated' )