相关的表,我有以下情况:如何组织数据库中的
table User (id, name)
table Belonging (id, name, color)
table UserBelonging (id, user_id, belonging_id)
现在,UserBelonging
是我加入连接User
和他Belonging
表。
的问题出现时,我想拉出来的一定User
全部家当,是红色。
我看到两种方法可以做到这一点:
- 获取所有
UserBelonging
某个用户,然后依次通过他们,并检查它们是红色 - 将一个额外的列这样的:
UserBelonging (id, user_id, belonging_id, color)
,然后在查询同一张桌子。
这两种方法似乎丑陋给我。有没有人有数据库表的经验,可以告诉我哪种方式更好,为什么或可能给我一个更好的解决方案?
感谢
请不要使用W3Schools的作为参考,HTTP: //w3fools.com/ – anderssonola