1

Possible Duplicate:
When to use comma-separated values in a DB Column?

I want to create similar articles script. My idea is that articles would be similar by ID. For example if article have ID = 1 for this article, similar article will be with similar_id = 1

Table example:

ID     Similar_ID   
1          0
2          0
3          1
4          1

Article with ID 1, will have 2 extra articles with ID 3 and 4.

How to model table if there are more than similar ID ?

Example:

ID     Similar_ID   
1          0
2          0
3          1,2
4          1,2,3
Community
  • 1
  • 1
Jonuux
  • 533
  • 1
  • 7
  • 20

1 Answers1

4

You should use two tables, the original one you have above, and a separate one that has one row per Article-Similar Article.

So your original table would be: Articles

    ID     Content   
    1          bla 
    2          blah 
    3          etc.
    4          whatever

And your other table would be as you have above: ArticlesSimilar

    ID     Similar_ID   
    3          1
    3          2
    4          1
    4          2
    4          3

You would ensure that the combination ID-Similar_ID were UNIQUE.

Stephen O'Flynn
  • 2,309
  • 23
  • 34