Hoping someone can help me out with this.
Lets say I have a table called incoming_data with 4 columns:
primary_key_id
serial_number
counter
selected_color
I get data from a source that fills this table. The primary key has its identity turned on so it is not repeating. I will get duplicate serial numbers with different selected colors.
The counter is ever increasing coming from the device.
So what I want to do is select all the data I received today, group the data by serial number and only get the record with the highest counter value.
Simple:
SELECT serial_number, MAX(counter)
FROM incoming_data
GROUP BY serial number
This works perfectly, except that I want to do something with the color information that I received.
If I add color to the select, then I get ALL the records since all the colors I received that day are different. That wont work.
If I could get the primary_key_id of the record then I could just query for the color but this doesn't work either since each primary_key_id value is different I get them all.
Any suggestions on a better technique for doing this?
Thanks!