user1286819
user1286819

Reputation: 91

MySQL LIKE more results than expected

Why does this LIKE-statement

WHERE configuration_key LIKE 'MODULE_SHIPPING_DP_%'

shows results like this:

MODULE_SHIPPING_DPD_STATUS
MODULE_SHIPPING_DP_STATUS
MODULE_SHIPPING_DPD_TAX_CLASS
MODULE_SHIPPING_DP_TAX_CLASS

I only wanted to get results with

MODULE_SHIPPING_DP_foobar

I dind't get it.

Upvotes: 1

Views: 54

Answers (2)

James Scholes
James Scholes

Reputation: 7906

_ is also a wildcard, matching one character. So you need to escape it.

WHERE configuration_key LIKE 'MODULE\_SHIPPING\_DP\_%'

Upvotes: 1

DessDess
DessDess

Reputation: 787

Because underscore _ is like the % except you only look for one character (cf documentation)

You need to escape the character by using \ before like this :

WHERE configuration_key LIKE 'MODULE\_SHIPPING\_DP\_%'

Upvotes: 2

Related Questions