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

  • Home
  • SEARCH
  • 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 6933967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:54:01+00:00 2026-05-27T11:54:01+00:00

Assume the following tables: TABLE: foo ========================= | foo_id | fk_id | name |

  • 0

Assume the following tables:

TABLE: foo
=========================
| foo_id | fk_id | name |
=========================
| 1      | 100   | A    |
| 2      | 100   | B    |
| 3      | 200   | C    |
| 4      | 200   | D    |
| 5      |       | E    |
| 6      |       | F    |
-------------------------

TABLE: foo_combo
===============================================
| foo_combo_id | parent_foo_id | child_foo_id |
===============================================
| 1            | 5             | 1            |
| 2            | 5             | 2            |
| 3            | 6             | 3            |
| 4            | 6             | 4            |
-----------------------------------------------

I need to get all foo where fk_id is 100 and all foo combinations that are made up of foo where fk_id is 100. Using the sample data provided, I need fk_id = 1,2, (these have fk_id = 100) and 5 (this is a foo made up of foo that have fk_id = 100).

What should the SQL look like?

EDIT 1:

Two queries I think that need to be combined:

SELECT * FROM foo WHERE fk_id = 100
SELECT foo.* FROM foo, foo_combo WHERE foo_combo.child_id IN (SELECT foo_id FROM foo WHERE fk_id = 100) AND foo.foo_id = foo_combo.parent_foo_id ???
  • 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-27T11:54:01+00:00Added an answer on May 27, 2026 at 11:54 am
    select foo_id from (
      select foo_id, fk_id from foo 
        union all
      select c.parent_foo_id, f.fk_id from foo_combo c inner join foo f on (c.child_foo_id = f.foo_id)
    ) foo_union where fk_id = 100;
    

    That should return something like

    +--------+
    | foo_id |
    +--------+
    |      1 |
    |      2 |
    |      5 |
    |      5 |
    +--------+
    

    The 5 is repeated because it matches twice. If you don’t want that, try adding “distinct” — ugly but serviceable.

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

Sidebar

Related Questions

Assume I have the following tables: TABLE: foo - foo_id (PK) TABLE: tag -
Assume the following table records: TABLE: foo ========================== | foo_id | foo_parent_id | ==========================
Assume I have the following tables and relationships: Person - Id (PK) - Name
For the sake of simplicity, let's assume the following tables exist: Table 1 -
Assume the following table structure: Tables: **Tasks** taskID int PK taskName varchar **Resources** resourceID
Let's assume that I have two tables... Foo and Bar. They contain the following
Given the following tables: CREATE TABLE tree ( id serial NOT NULL, name character
Let's assume I have the following table class: class TestTable(tables.Table): id = tables.Column() description
Let's assume I have 3 tables in a MySQL table with the following fields.
Assume I have the following style table, col1 col2 and col3 have same value

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.