douyou2234 2012-07-21 05:54
浏览 23
已采纳

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

  • 写回答

1条回答 默认 最新

  • dongyong1400 2012-07-21 06:56
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大