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?
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.