mysql Find_in_set更好或单个查询检查更好

时间:2013-05-20 07:46:46

标签: php mysql

我有mysql find_in_set的问题,因为在名为menu_table的表中,我想存储以下数据。但我想将menu_ids的值与另一个表的单个menu_id相匹配

mt_id menu_ids
---------------
 1    4,5,6,
 2    7,8,
 or 
mt_id menu_ids
----------
1      4
2      5

然后我不明白如何存储值,哪个是检查menu_ids的更好解决方案?

1 个答案:

答案 0 :(得分:2)

不要存储以逗号分隔的值。这是一个糟糕的架构设计。我建议你像这样设计表格,

菜单表

  • MenuID(PK)
  • OtherColumns ...

其他表格

  • MTID(PK)
  • OtherColumns ...

Menu_Other table

  • MTID(带有MenuID列的PK)
  • MenuID(FK)

示例记录

菜单表

MenuID  OtherColumn
1       aaaa
2       bbbb

其他表格

MTID    OtherColumns
1       a   
2       b
3       c
4       d
5       e
6       f

Menu_Other Table

MenuID  MTID    
1       1
1       2
2       3
2       4
2       5
相关问题