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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:47:55+00:00 2026-05-13T18:47:55+00:00

Hoping that someone here will be able to provide some mysql advice… I am

  • 0

Hoping that someone here will be able to provide some mysql advice…

I am working on a categorical searchtag system. I have tables like the following:

EXERCISES
    exerciseID
    exerciseTitle

SEARCHTAGS
    searchtagID
    parentID ( -> searchtagID)
    searchtag

EXERCISESEARCHTAGS
    exerciseID (Foreign key -> EXERCISES)
    searchtagID (Foreign key -> SEARCHTAGS)

Searchtags can be arranged in an arbitrarily deep tree. So for example I might have a tree of searchtags that looks like this…

Body Parts
    Head
    Neck
    Arm
        Shoulder
        Elbow
    Leg
        Hip
        Knee
Muscles
    Pecs
    Biceps
    Triceps

Now…

I want to select all of the searchtags in ONE branch of the tree that reference at least ONE record in the subset of records referenced by a SINGLE searchtag in a DIFFERENT branch of the tree.

For example, let’s say the searchtag “Arm” points to a subset of exercises. If any of the exercises in that subset are also referenced by searchtags from the “Muscles” branch of SEARCHTAGS, I would like to select for them. So my query could potentially return “Biceps,” “Triceps”.

Two questions:

1) What would the SELECT query for something like this look like? (If such a thing is even possible without creating a lot of slow down. I’m not sure where to start…)

2) Is there anything I should do to tweak my datastructure to ensure this query will continue to run fast – even as the tables get big?

Thanks in advance for your help, it’s much 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-05-13T18:47:56+00:00Added an answer on May 13, 2026 at 6:47 pm

    Alternatively, use modified preorder tree traversal, also known as the nested set model. It requires two fields (left and right) instead of one (parent id), and makes certain operations harder, but makes selecting whole branches much easier.

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

Sidebar

Related Questions

I have a semi-complicated problem and hoping that someone here will be able to
I'm having some strange drawing artefacts that I'm hoping someone might be able to
I am really hoping someone will be able to help me here. I am
I'm hoping someone here will be able to aid me with my struggles with
Here's a JSFiddle that breaks uniquely in Internet Explorer 9. I'm hoping someone has
I'm hoping (and pretty sure that) someone out there is much better at MySQL
I'm having with some margin or padding issues with IE8 that I'm hoping someone
I'm hoping someone have encountered this problem before and will be able to help
I have a more generic question, so I'm hoping someone here has some info
I am hoping that someone maybe able to help me. I need to 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.