www.webdeveloper.com
Results 1 to 2 of 2

Thread: IN() Issues

  1. #1
    Join Date
    Oct 2009
    Posts
    65

    Question IN() Issues

    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?

  2. #2
    Join Date
    Dec 2002
    Location
    St. Louis, MO, USA
    Posts
    1,582
    It's the difference between INT and VARCHAR. If you are supplying only one INT id, it's no problem. If you provide several and they are comma delimited, the database thinks you're looking for VARCHARs. That's not entirely accurate, but it's the best way I can articulate it.
    |||||
    o . Q
    ___ "You live and you learn; or you don't live long." - Lazarus Long

    ^_^

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles