mysql select query within a serialized array

前端 未结 14 1297
忘了有多久
忘了有多久 2020-11-29 07:51

I\'m storing a list of items in a serialized array within a field in my database (I\'m using PHP/MySQL).

I want to have a query that will select all the records that

14条回答
  •  自闭症患者
    2020-11-29 07:58

    Well, i had the same issue, and apparently it's a piece of cake, but maybe it needs more tests.

    Simply use the IN statement, but put the field itself as array! Example:

    SELECT id, title, page FROM pages WHERE 2 IN (child_of)
    

    ~ where '2' is the value i'm looking for inside the field 'child_of' that is a serialized array.

    This serialized array was necessary because I cannot duplicate the records just for storing what id they were children of.

    Cheers

提交回复
热议问题