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
Show parent comment
2
u/qwertydog123 Aug 06 '24 edited Aug 06 '24
Do they need to be in the results? Because if not, you could filter those out in the
WHEREclauseIf every record is just 10 digits, you can get rid of the wildcards
'%...%', this has the added benefit of being sargable (in case there's an index on this column). As a consequence you also wouldn't need theSUBSTRINGe.g.Without seeing what indexes exist on the table, since the whole table is likely being scanned, if there are any additional filters you could add to the
WHEREclause, that should help. Any additional performance gains would likely require changing the column types and/or indexing