600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > 怎么在mysql中打开表存信息 我应该如何存储用户的“收藏夹”在mySQL表?

怎么在mysql中打开表存信息 我应该如何存储用户的“收藏夹”在mySQL表?

时间:2023-08-21 02:23:44

相关推荐

怎么在mysql中打开表存信息 我应该如何存储用户的“收藏夹”在mySQL表?

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 entry?

USER_ID SKU_Favorited

001 10016

001 10067

024 10016

001 10010

024 16779

Seems redundant to have to enter the same user twice, but is this what I should do? Then in lookup I just SELECT sku WHERE user id... and find all SKUs next to that number?

解决方案

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

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。