Query to find max value of one column based on two other columns and return add'l columns
Posted on 2014-02-27
Confusing enough title?
I have a table that has the following columns:
id, date, store, upc, price, price_type, start_date, end_date, timestamp
The only column that is unique is the id column. There are multiple rows that have the same store and upc values.
I want to be able to return the entire row of data that has the highest timestamp based on the combination of the store and upc columns.
The following query works to find the store and upc combo that have the highest timestamp, but of course group starts throwing a fit once I try to add additional columns to return.
select store, upc, MAX(timestamp) max_timestamp
GROUP BY store, upc