Finding exact value from a comma separated string in PHP MySQL

前端 未结 1 820
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-12 14:11

I have a product table which contains a field called \'categories\' to save product related category ids as comma separated values. I am using regexp to search products from

1条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-12 14:43

    Use

    WHERE categories REGEXP "(^|,)4(,|$)"
    

    This matches 4 if surrounded by commas or at the start/end of the string.

    In your present version, both commas are entirely optional, so the 4 in 24 matches.

    0 讨论(0)
提交回复
热议问题