Pars
Pars

Reputation: 5272

MySQL Left() or SUBSTRING()?

Both of these queries will produce same result. But which one is better, faster.

SELECT LEFT(textField, 100) AS first100Chars

SELECT SUBSTRING(textField, 1, 100 )

Thanks.

Upvotes: 15

Views: 15189

Answers (2)

Pankhuri Kaushik
Pankhuri Kaushik

Reputation: 332

Substring will take little more time than left function. Though your case is straight forward use left function only.

Upvotes: 1

Konstantin
Konstantin

Reputation: 3294

By itself there is little difference, however left can potentially utilize an index while substring cannot.

Upvotes: 16

Related Questions