user1043994
user1043994

Reputation:

Profile data in one or many tables in MySQL

Let´s say I create something familiar to Facebook where the user can add interests to his or hers profile.

One way to do this is to have a field called Interests in the profile table and list the interests ID. So that the field Interests would look like this: 1,4,43,66 where each number refers to an interest in the interest table. I would then have to explode the interest fields using PHP to get each interest´s name.

Another way to do this is to have a third table that looks like this:

profileID, interestID
1          1
1          4
1          43
1          66

Which would achieve the same thing.

I haven´t worked much with databases. I use MySQL. Which is the best way to go? Let me know if you don´t understand.

Thanks for your help!

Upvotes: 0

Views: 46

Answers (1)

Art
Art

Reputation: 5924

Your second approach would be the one to go with. It all really depends on your requirements, but the second one is more flexible. With both you can answer the question: "What interests does user X have?", but only with the second one can you answer "What users are interested in Y?". Also, it allows you to do a join, so instead of doing 2 lookups/queries, you can do one.

Upvotes: 1

Related Questions