简体   繁体   中英

Grouping rows from one MySQL table in another

I'm trying to build a recipe web-application, and want to build the recipe 'Steps' into a MySQL table, which can then be grouped together into 'Stages' - ie multiple steps. Building the base table is trivial as it's all in CSV anyway from a previous piece of work, but what i'm trying to understand is how can I build a second table which will be comprised of several rows from table 1?

TABLE 1 ('Steps'):

Step_#      Step_Desc     Consumable     Tool      Recipe
--------------------------------------------------------
  1       Add ingredient    Sugar         Bowl        n/a
  2       Add ingredient    Butter        Bowl        n/a
  3       Mix base ings.     n/a         Mixer       FN_1
  4       Add ingredient     Eggs         Bowl        n/a
  5       Add ingredient    Flour         Bowl        n/a
  6       Mix ingredients    n/a         Mixer       FN_1
  7       Transfer to tray   n/a          Tray        n/a
  8       Place in oven      n/a         Oven      200C/50min
  9       Remove to cool     n/a         Rack       30 min
--- and so on for 400+ steps

TABLE 2 ('Stages') would then be a series of rows, collecting these various steps into different groups for example:

Prepare Sponge: Step_# 1,2,3,4,5,6,7 {from Table 1}

Bake and Rest: Step_# 8,9 {from Table 1}

Dice fruit and chill: Step_# 193,194,306 (etc - table 1 will be huge and this example was quite limited and boring).

Does anyone have a suggestion as to how to achieve this (foreign keys/logic?) in MySQL? Is this even possible?

Cheers

EDIT: Each step will need to be called in to multiple stages. (Thanks Dan).

您可以在steps表中添加名为stage_id新列,并在此列中保留阶段ID。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM