We’ve got an “audit log” table that stores each item’s price every day. Here’s some sample data:
1 - Item 587 - $19.99 - 12/1/2012
2 - Item 587 - $19.99 - 12/2/2012
3 - Item 587 - $18.99 - 12/3/2012
4 - Item 587 - $18.99 - 12/4/2012
5 - Item 587 - $20.99 - 12/5/2012
6 - Item 587 - $19.99 - 12/6/2012
7 - Item 587 - $19.99 - 12/7/2012
8 - Item 587 - $17.99 - 12/8/2012
9 - Item 587 - $17.99 - 12/9/2012
10 - Item 587 - $17.99 - 12/10/2012
This works fine, however, this table is growing too quickly. We now need a T-SQL script to remove duplicate rows. The dataset after the script should be like this:
1 - Item 587 - $19.99 - 12/1/2012
3 - Item 587 - $18.99 - 12/3/2012
5 - Item 587 - $20.99 - 12/5/2012
6 - Item 587 - $19.99 - 12/6/2012
8 - Item 587 - $17.99 - 12/8/2012
It seems like a GROUP BY or DISTINCT is called for, but I’m unsure of how to start.
You can change your partition preferences as necessary. This will delete directly from your table in one query.