Comma separated value & wildcards in mysql

前端 未结 2 1866
没有蜡笔的小新
没有蜡笔的小新 2021-01-24 21:18

I have a value in my database with comma separated data eg.

11,223,343,123

I want to get the data, if it match a certain number (in this exampl

相关标签:
2条回答
  • 2021-01-24 21:54

    The wp_post_meta table is designed to hold loads of values, and for that simple reason (and because of database normalization, you should not never comma seperated lists as values in databases.

    If you absolutely must use it this way, there are some mySQL functions, one being FIND_IN_SET.

    0 讨论(0)
  • 2021-01-24 21:57

    Storing stuff in a comma separated list usually is a bad idea, but if you must, use the FIND_IN_SET(str,strlist) function.

    WHERE FIND_IN_SET('223',wp_postmeta.meta_value)
    

    If you can change your database and normalise it, you would get faster results. Create an extra table that links meta_values to your primary_id in your table.

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