Search code examples
mysqlsql-like

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.


Solution

  • 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\_%'