How should I store user “favorites” in mySQL table?

后端 未结 2 1673
[愿得一人]
[愿得一人] 2021-02-04 20:31

I keep reading that I should store this in a separate table \"with one value per line\". What does this mean exactly? Like this - So that each \"favoriting\" gets another user e

相关标签:
2条回答
  • 2021-02-04 21:02

    It is called relational databases that are in 3-rd normal form

    You have one table with users.

    //users
    id | username | password
    

    And table with favorites

    //favorites
    id | userid | Favorited
    

    here how you get it:

    select * from favorites inner join users on favorites.userid=users.id where users.id=1

    0 讨论(0)
  • 2021-02-04 21:06

    Yes, that is exactly how you would do it. I wouldn't consider it redundant.

    0 讨论(0)
提交回复
热议问题