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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:16:56+00:00 2026-06-14T22:16:56+00:00

I have 3 tables as follows: Table: sys_department Columns: dept_id dept_name row: 1 Support

  • 0

I have 3 tables as follows:

Table: sys_department
Columns:   dept_id   dept_name
row:       1         Support
row:       2         HR
row:       3         Billing

Table: sys_groups
Columns:   group_id   group_name
row:       1          Manager
row:       2          Intern
row:       3          Staff

Table: group_dept_access
Columns:   group_id   dept_id
row:       1          3
row:       2          1
row:       2          2 
row:       3          1
row:       3          2 

I would like to run a query to fetch the list of group names with the department names they have access to.

So since group_id of 3 in group_dept_access has both 1 and 2 listed as dept_id that group would return back with it’s group_name of Billing along with the department names Support and HR.

I was able to run the query to fetch the group_name when selecting group_dept_access using JOIN, but I don’t know how to query all three tables and get the departments as well.

Unfortunately I can’t change the table structure as it would be nice if say the 3rd table didn’t have multiple entries for each group, but it’s an existing system so would break if changed. Also using MySQL 5.1.x on current server, but in future will be using 5.5.x. if such a query is done differently between versions how would each be done?

Any help appreciated as this will help me make other similar queries that I will be performing. An explanation on how it’s done would be great too so that I can learn how this 3 table query is done. Thank you 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-14T22:16:57+00:00Added an answer on June 14, 2026 at 10:16 pm

    Try this:

    SELECT sg.group_name, A.dept_name 
    FROM sys_groups sg 
    INNER JOIN (SELECT gda.group_id, GROUP_CONCAT(sd.dept_name SEPARATOR '|') dept_name
                FROM group_dept_access gda 
                INNER JOIN sys_department sd ON gda.dept_id = sd.dept_id 
                GROUP BY gda.group_id) AS A ON sg.group_id = A.group_id 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables as follows: tblCountry (countryID, countryCode) tblProjectCountry(ProjectID, countryID) The tblCountry table
i have 2 tables, users and follows. table follows has a column named status.
I have a HTML table as follows. I want retrieve row values from this
I have two mySQL tables as follows: [product] table P_id | Name | Quantity
I have two tables as follows, Table name Payment_transaction having column name as payment_ref_id,
I have two tables that look as Follows: Person (Table Name) Name1/Phone1/Email1/Address1/Organization1/Notes1 (Fields) Organization
I have two tables members and dep whose description are as follows: TABLE members:
I have data from two tables in a members system as follows: Table: listuser
I have two tables as follows: CREATE TABLE customer ( id INT NOT NULL
I have 2 tables: Lecturer and Department . The Lecturer table has these columns:

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.