How to Use a SQL Rank Function to Deduplicate a Table