Say I have some data stored in an audit table, where triggers on the main data table write all invoice record updates to this audit table. The audit table contains this data:
InvoiceID CustomerID ItemSold AmountSold SalesPerson ModifyDate
1001 96 Widget 800 Robert 2001-1-1
1006 85 Thinger 350 Phil 2001-1-8
1001 96 Widget 800 Bobby 2001-1-9
1005 22 Widget 400 Robert 2001-1-10
1006 44 Thinger 500 Mike 2001-2-5
1001 96 Widget 250 Robert 2001-6-4
And I want to write a query which will identify whenever the SalesPerson field changes, for any particular InvoiceID (eg: whenever a salesman changes the sale to his name).
So in the example above, I'd like to identify the change which took place on 2001-1-9, where the sale for InvoiceID 1001 went from Robert to Bobby, and the change on 2001-6-4 where it went back to Robert from Bobby...so two changes for that particular ID. And I'd also like to identify the change on 2001-2-5 where the sale for InvoiceID 1006 went from Phil to Mike.
How can I write a SQL query which will identify/highlight these changes?
The table doesn't currently contain a primary key, but I can add one if needed.