Mysql中一对多所需的示例[关闭]

I have 2 tables call products and combo. products table will have all the products data's like sn,product name, product price, product image...etc

and combo table is to group the products like first product's id second product's id third product's id will be in a one group called Set 1

i need to get the combo products details using one to many in mysql.

how it can be done

Thank in advanced

You can use the lookup table pattern:

You can try designing the schema so that each product => combo pair is one row.

For example:

product_id, combo_id
product_1, combo_1
product_2, combo_1
product_3, combo_1
product_1, combo_2

When you do a select from the tables, you'll want to use some very good joining and grouping:

"select product.product_name, combo.combo_id from combo, product where product.product_id = combo.combo_id and combo_id = 'combo_1'";

Anyway, read up on methods to do lookup tables. This is just my suggestion of how you might want to design the schema.