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 6625983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:50:23+00:00 2026-05-25T21:50:23+00:00

two tables: Exercises ——— Exercise ID 1 ExerciseTargettedMuscles ———————— exerciseID muscleID 1 10 1

  • 0

two tables:

 Exercises
    ---------
    Exercise ID 
    1

ExerciseTargettedMuscles
------------------------
exerciseID       muscleID
   1               10
   1               20
   1               30

I need to grab exercises that include all of the muscles it targets.
so, if exercise a has exerciseID=1 and has muscleIDs=10,20, and 30, then the result of the query should be exercises with (at least) muscleIDs=10,20, and 30.

What confuses me is the multiple-to-multiple row comparing. The way that works in my head is to just make sure that there doesn’t exist a muscle in the main exercise that is not present in the selected exercise(s). How do you loop through every one to see if it is not in the selected exercise?

  • 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-05-25T21:50:23+00:00Added an answer on May 25, 2026 at 9:50 pm

    Using HAVING to filter your results to only include those with at least the desired muscles:

    select exerciseID
    from ExerciseTargettedMuscles
    where muscleID in (10, 20, 30)
    group by exerciseID
    having count(muscleID) = 3
    

    The 3 should match the number of muscles.

    The WHERE gives you the exercises that have any of the desired muscles. Then they are grouped into one group for each exercise. Finally the HAVING is used to include only those groups that have all (rather than just some) the muscles.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables that are joined together. A has many B Normally you
I have two tables: users and user_depts. Let's say (for this question) that users
I need to join two tables based on columns with different types. The first
Got two tables: users(id, column) and objects(user_id, column) . How to extract all users
DESCRIPTION I have two datasets with information that I need to merge. The only
Given two tables: (incoming greatly reduced/simplified example that exhibits the key problem) app_data represents
Two tables: COURSE_ROSTER - contains COURSE_ID as foreign key to COURSES USER_ID as field
Two tables: table_a ------- table_a_id: (primary, int) table_b ------- table_a_id: (index, int, from table_a)
Consider two tables transaction and category each having their own ID and information. A
Given two tables, one for workers and one for tasks completed by workers, CREATE

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.