Which will perform better when searching for a key with a specific prefix in MySQL? ;-
i) where left(X,2)="AB"
or
ii) where X like "AB%"
Assuming you have an index on the column, the second is faster. The database can use an index when you use LIKE but it cannot when you use LEFT. In technical terms, LIKE is sargable but LEFT is not. You can find more information here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With