我应该如何存储用户的“收藏夹"在mySQL表? [英] How should I store user "favorites" in mySQL table?

查看:429
本文介绍了我应该如何存储用户的“收藏夹"在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

似乎不得不两次输入相同的用户,这是多余的,但这是我应该做的吗?然后在查找中,我只是SELECT sku WHERE用户ID ...,并找到该编号旁边的所有SKU?

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

您与用户有一张桌子.

//users
id | username | password

带有收藏夹的表

//favorites
id | userid | Favorited

如何获取它:

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

这篇关于我应该如何存储用户的“收藏夹"在mySQL表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆