In SQL, tables are not ordered. If you do not use the ORDER BY , database engines are allowed to return records in any order that they consider to be the fastest (for example, a coverage index can have data in a different order, and sometimes even SQLite automatically creates temporary coverage indexes).
If the steps have a specific order in a specific recipe, you need to save this information in a database.
I would suggest adding this to the recipe table:
recipeId | step | stepOrder --------------------------- 1 | 1 | 1 1 | 2 | 2 1 | 3 | 3 2 | 4 | 1 2 | 2 | 2
Note: The recipe table keeps the relationship between recipes and steps, so it should be called recipe-step . The recipe-step table is not dependent on recipes, so it should be called step . You probably need a table that stores information about recipes that does not depend on steps; this table should be called recipe .
source share