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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:37:12+00:00 2026-06-17T00:37:12+00:00

Im finding it very hard to learn how to build more complicated queries in

  • 0

Im finding it very hard to learn how to build more complicated queries in mySQL.

Hopefully, through this question, I can gain some more insight as to how to develop multi-level queries inside a single query.

I have a tagging system.

tbl1: ktbridge
ktbridge_id
threads_id
keywords_id

tbl2: threads
threads_id
subject
etc

tbl3: keywords
keywords_id
keyword
related_id

Above is my current set up.

For data, I have:

INSERT INTO `ktbridge` (`ktbridge_id`, `threads_id`, `keywords_id`) VALUES
(1, 1, 9);

INSERT INTO `keywords` (`keyword_id`, `keyword`, `related_id`) VALUES
(5, 'Sports', 0),
(6, 'Baseball', 5),
(7, 'football', 5),
(8, 'Curling', 5),
(9, 'Pitchers', 6),
(10, 'Catchers', 6),

INSERT INTO `threads` (`threads_id`, `subject`, `body`, `users_id`, `timestamp`, `replystamp`) VALUES
(1, 'Sports - Baseball - Pitchers - Subject', 'Sports - Baseball - Pitchers - Body', 1, '2013-01-09 14:09:40', '0000-00-00 00:00:00');

The goal here, is to return the threads that are related to the keyword_id that is provided.

The tough part is that if “baseball” is selected, it returns baseball threads. However, if “sports” is selected, it returns all threads below it, based on the “related_id” in the keywords table. So it would return all threads based on baseball, football, and curling.

Is this a possibility? Or will it require multiple queries? Thanks in advance!

  • 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-17T00:37:13+00:00Added an answer on June 17, 2026 at 12:37 am

    It does require multiple queries, but you can nest them and select from within the inner select. I think the following should work (or at least get you started). Note that this is MySQL, but should be portable to other RDBM systems:

    SELECT * FROM `threads` WHERE `threads`.`threads_id` IN (
      SELECT `threads_id` FROM `ktbridge` WHERE `ktbridge`.`keywords_id` IN (
        SELECT `keywords_id` FROM `keywords` 
          WHERE `keywords`.`id` = 5 OR `keywords`.`related_id` = 5
        )
      );
    

    MySQL doc reference for “IN”

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

Sidebar

Related Questions

Ok this one should be fairly simple but Im finding it very hard. I
It sounds like such a easy task but I am finding this very hard
I'm very new to PHP and having a hard time finding this answer as
I am newbie and finding it very hard to grasp the syntax of Class
I really like the magento structure but finding things is very hard ;) My
I've been having a very hard time finding good examples of UIScrollView. Even Apple's
I'm finding this kind of overriding after a new in java code very often
I am using Rail 3 and I am finding it very hard to do
I am having a very hard time finding resources that talk about the windows
I am finding it very hard to understand the way the inverse of the

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.