Girish Pawar
Girish Pawar

Reputation: 1

mysql Find_in_set is better or single query check is better

i have problem with mysql find_in_set, because in table named menu_table in which:i would like to store following data. But i want to match the value of menu_ids to single menu_id of another table

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

then i don't understand how to store the value and which is better solution for checking menu_ids?

Upvotes: 0

Views: 102

Answers (1)

John Woo
John Woo

Reputation: 263843

Do not store values separated by a comma. It's a bad schema design. I suggest the you design the table like this,

Menu Table

  • MenuID (PK)
  • OtherColumns...

Other Table

  • MTID (PK)
  • OtherColumns...

Menu_Other table

  • MTID (PK with column MenuID)
  • MenuID (FK)

Example Records

Menu Table

MenuID  OtherColumn
1       aaaa
2       bbbb

Other Table

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

Upvotes: 2

Related Questions