The difference between a SQL solution and @Ksharp hash solution will most likely come down to speed.
The hash solution should be faster, but you trade it for code complexity.
If you're doing this once stick with the SQL. If you need to set up a process, explore the hash solution.
... View more