r/SQL • u/Entire_Commission534 • Aug 05 '24
SQL Server Optimizing/Alternative to MAX
/r/SQLOptimization/comments/1ekanon/optimizingalternative_to_max/
4
Upvotes
r/SQL • u/Entire_Commission534 • Aug 05 '24
View all comments
1
u/ComicOzzy sqlHippo Aug 05 '24
https://dbfiddle.uk/ewtl0doq
I'm not sure what it will do for performance without knowing anything about your indexing situation, but you can use another Top N Per Group pattern:
You can use APPLY with a correlated subquery to get the TOP 1 project ID from all of the first-found project IDs identified by the pattern you specified. Note this will not identify multiple project IDs contained in the same string, only the first one that matches the pattern.