Reputation: 41
I'm looking to set up a favorites table properly for a system where the favorited user's id is added to the table when the "add to favorites" button is clicked.
If each user only ever had 1 favorite it would be simple, but since each user would have multiple favorites I can't figure out how to make that work.
I have a USERS table with columns for User_ID, Username, Email Address, Password. I'd like to be able to add another user as a "Favorite" and be able to go to "My Favorites" page where they show up as a list.
Any help much appreciated. Thank you.
Upvotes: 0
Views: 386
Reputation: 444
You just need a table, we'll call User_Favorites
, with columns User_ID
and Favored_User
.
The two fields together would be the PK for the table and each, separately, would be a FK back to Users
.
This allows you to have a user that 'favorited' every other user in the system
Upvotes: 3
Reputation: 2632
Create another table, as a junction table. Many users have many bookmarks
Surrogate Key|UserWithBookmarkID(USER_ID)|UserThatIsBookmarkID(USER_ID)
Upvotes: 0