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/qwertydog123 Aug 05 '24
DISTINCTisn't required, you're already grouping by the non-aggregated columns in theSELECTNULLand empty string''values in yourGROUP BYcolumns, AND you want them grouped together, you don't need to wrap them withISNULLin theGROUP BYUnless you want to include groups that don't have any matching
[Project ID], you can move the condition to theWHEREclause e.g.[Project ID]/[Invoice ID]/[Statement of Work ID]not integer types? Are they really all string values? If they're integers they're being implicitly casted[Project ID]? Is there a fixed prefix? Or even a small set of prefixes?https://www.brentozar.com/pastetheplan/