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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:02:01+00:00 2026-06-01T09:02:01+00:00

I want to join a table which contains n:m relationship between groups. (Groups are

  • 0

I want to join a table which contains n:m relationship between groups. (Groups are defined in a separate table).
This table only has entries listing a member_group_id and a parent_group_id.

Given this structure:

id(int) | member_group_id(int) | parent_group_id(int)

The “base” query looks like this:

select p1.group_id, p2.group_id, p1.member_group_id, p2.member_group_id
from group_member_group as p1 
join group_member_group as p2 
on p2.member_group_id = p1.member_group_id

The “base” query correctly shows all relationships (I checked by doing it manually.)

The problem is when I try to apply a where clause to this query to filter for a specific group as “point of origin” (the first group for which I want all parent groups) it returns only the closest parents. For example like this:

select p1.group_id, p2.group_id, p1.member_group_id, p2.member_group_id
from group_member_group as p1 
join group_member_group as p2 
on p2.member_group_id = p1.member_group_id
where p1.group_id = 1

Can anyone give a clue how I can fix this? Or a different approach to realize this. (I suppose I could always do this in my C++ source code on the server side but I would have to transfer a entire table which has a high growth potential to the application server.)

UPDATE:

select p1.group_id, p2.group_id, p1.member_group_id, p2.member_group_id
from group_member_group as p1 
join group_member_group as p2 
on p2.group_id = p1.member_group_id

Typing mistake confirmed. Now I don’t get past first level of inheritance period. Thanks at denied for pointing that out.

UPDATE2: Expected Result

id | group_id | member_group_id
--------------------------------
1  |    1     |    2
2  |    2     |    3
3  |    3     |    4
4  |    4     |    5
5  |    5     |    6
6  |    6     |    7

expected result:

ids

2
3
4
5
6
7
  • 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-01T09:02:02+00:00Added an answer on June 1, 2026 at 9:02 am
    on p2.member_group_id = p1.member_group_id
    

    it looks like mistake.

    Maybe you wanted to type

    on p2.parent_group_id = p1.member_group_id
    

    Maybe you should look for Nested Set Model for parent-child relationships.

    It’s much easier to make queries like this in that model.

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

Sidebar

Related Questions

I have a table 'service' which contains details about serviced vehicles. It has an
I'm trying to query a table which has a column that contains straight xml
I want to select everything from table one, which contains a column JID. These
I created a simple query which contains a JOIN, and this JOIN 'makes' some
I want to join two tables (below) which i get. But then I want
I have two tables which I want to join together using a left outer
I want to join 2 tables 'addresses' and 'user_info' on user_id and app_id (which
I want to join my CHEESE table with FRESHNESS to get CHEESE and FRESHNESS
I want to left join 2 tables. So all attributes of left table should
I want to update a column in a table making a join on other

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.