Comparing Mysql using left (X, 2) = "AB" or X as "AB%" for speed?

What will work better when searching for a key with a specific prefix in MySQL ?; -

i) where left (X, 2) = "AB"

or

ii) where X is like "AB%"

+5
source share
1 answer

Assuming you have an index in a column, the second is faster. The database can use the index when you use LIKE, but you cannot use LEFT. Technically speaking, LIKE is mobile, but LEFT is not. You can find more information here .

+6
source

All Articles