I have two tables.
User_types
- (1)individual
- (2)business
- (3)student
Relationship_cat
- cat_id
- cat_name
- user_id
- user_type
First with Relationship_cat, i want an entry to look like this
cat_id(1), cat_name(interests) ,user_id(ANy user), user_type(only 1 and 3)
cat_id(2), cat_name(news) ,user_id(ANy user), user_type(only 2 and 3)
etc
With user_type i believe i could set it to 0 as default so it’s not constrained to any user. How do I go about the "relationship_cat > user_type" case? Do I use a comma separated list of values? Is it efficient? And what if there are many User_types entries increase?
You should use a many-to-many join table. So your schema might look like this:
user_types
categories
categories_to_user_types
Any time you may think about using comma-separated values like you mentioned, this should be a sign to you to further normalize your tables. What I have shown is typically the best way to express a many-to-many relationship between tables.