IN() Issues

Discussion in 'MySQL' started by bonecone, Jun 3, 2011.

  1. #1
    I'm creating a link directory database where links can belong to multiple categories. A link will have an INT id field as PRIMARY KEY and a VARCHAR parent_d field with a comma separated list of category ids (12,3,45,etc) that it belongs to.

    So if I want to find all links that belong to category 83 I use

    SELECT * FROM links_table WHERE 83 IN(parent_id)

    But this doesn't work if the parent_id field contains more than one value. if parent_id = "83" then it works. If parent_id = "83,12" the sql query doesn't find it. What am I doing wrong?
     
    bonecone, Jun 3, 2011 IP
  2. koko5

    koko5 Active Member

    Messages:
    394
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    70
    #2
    Hi, parent_id must be set and you should use FIND_IN_SET()
     
    koko5, Jun 3, 2011 IP