Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8323193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:38:54+00:00 2026-06-08T23:38:54+00:00

I have a kitchen recipe script I’m working on, and am having trouble accessing

  • 0

I have a kitchen recipe script I’m working on, and am having trouble accessing fields in joined tables. My tables are setup as follows:

ingredients
-----------
ingredient_id (pk)
ingredient_name (pk)
ingredient_calories (pk)

recipes
-------
recipe_id (pk)
recipe_name (pk)

meals
-----
meal_id (pk)
meal_name (pk)

recipe_has_ingredients
----------------------
recipe_id (fk)
ingredient_id (fk)

meal_has_recipes
----------------
meal_id (fk)
recipe_id (fk)

a recipe contains many ingredients, and a meal contains many recipes.

THE PROBLEM IS:

While I can SELECT SUM(ingredient_calories) FROM recipe_has_ingredients, I cannot figure out how to do this via the meal_has_recipes table (to calculate total calories in a meal).

Any help is greatly appreciated 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T23:38:55+00:00Added an answer on June 8, 2026 at 11:38 pm

    You have over constrained the primary keys on the fact tables ingredients, meals and recipes. Just use the id field as the pk.

    You can create a unique constraint on any name field.

    The recipe has ingredient table should have recipe_id and ingredients_id as a compound primary key.

    The meal has recipes table should have meal_id and recipe_id as a compound primary key.

    The query for calories for a meal is now

     select meal_name, sum ( ingredients_calories)   from
    
        meals, meal_has_recipes, recipes_has_ingredients, recipes, ingredients
    
       where
    
          meal_name = ' good   food'   
    
          and   meal_has_recipes.meal_id =  meals.meal_id 
    
          and   meals_has_recipes.recipe_id = recipes.recipe_id
    
          and   recipes.recipe_id = recipes_has_ingredients.recipe_id
    
          and    ingredients.ingredients_id = recipes_has_ingredients.ingredients_id;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of whitelisted words: kitchen chair table ; Given a text,
Have 2 tables in Access 2007, both lists of certain tasks to be accomplished.
On perusing the Sencha Touch kitchen sink, I noticed that they have somehow disabled
Have finally got a responsive site working (of a fashion). What I want to
I have implemented a sencha touch phone gap application on ipad. using the kitchen
To facilitate building a kitchen sink installer for our app we have several large
I have a Access DB and 2 tables I need to set the relationships
I'm writing a program for kitchen/recipe management. As of now, the program can add
have written this little class, which generates a UUID every time an object of
Have a procedure which looks like Procedure TestProc(TVar1, TVar2 : variant); Begin TVar1 :=

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.