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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:27:36+00:00 2026-06-16T16:27:36+00:00

I have a standard many to many relationship between two tables, linked using a

  • 0

I have a standard many to many relationship between two tables, linked using a third linking table. Is there anyway to JOIN the linked ids into one record with a query?

I realize I can process a typical join and build a new list with this, just wondering if it can be done with a query. Example:

EventID | EventName | EventTypeIDs

1 | Party | 1,2,3

Events
+-------------+-------------+
| Field       | Type        |
+-------------+-------------+
| EventID     | INT         |
| EventName   | varchar(45) |
+-------------+-------------+

EventTypes
+-------------+-------------+
| Field       | Type        |
+-------------+-------------+
| id          | INT         |
| value       | varchar(25) |
+-------------+-------------+

EventTypeLink
+-------------+-------------+
| Field       | Type        |
+-------------+-------------+
| id          | INT         |
| EventID     | INT         |
| EventTypeID | INT         |
+-------------+-------------+
  • 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-16T16:27:37+00:00Added an answer on June 16, 2026 at 4:27 pm

    Yes there is. Use the GROUP_CONCAT() like so:

    SELECT
      e.EventId,
      e.EventName,
      GROUP_CONCAT(t.Id SEPARATOR ',') AS EventTypeIDs
    FROM Events e
    INNER JOIN EventTypeLink l ON e.EventId = l.EventId
    INNER JOIN EventTypes    t ON l.EventTypeId = t.Id
    GROUP BY   e.EventId,  
               e.EventName;
    

    SQL Fiddle Demo

    This will give you:

    | EVENTID | EVENTNAME | EVENTTYPEIDS |
    --------------------------------------
    |       1 |     Party |        1,2,3 |
    

    Note that: If you need to inclue those events with no types, use a LEFT JOIN instead, with IFNULL like so:

    SELECT
      e.EventId,
      e.EventName,
      GROUP_CONCAT(IFNULL(t.Id,0) SEPARATOR ',') AS EventTypeIDs
    FROM Events e
    LEFT JOIN EventTypeLink l ON e.EventId = l.EventId
    LEFT JOIN EventTypes    t ON l.EventTypeId = t.Id
    GROUP BY   e.EventId,  
               e.EventName;
    

    SQL Fiddle Demo for those with no types

    This will give you something like:

    | EVENTID |        EVENTNAME | EVENTTYPEIDS |
    ---------------------------------------------
    |       1 |            Party |        3,2,1 |
    |       2 | EventWithNoTypes |            0 |
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Postgres v. 8.4.2. I have a standard three-table setup for a many-to-many relationship.
In my Rails app I have a fairly standard has_many relationship between two entities.
I have a standard many-to-many relationship between users and roles in my Rails app:
I have two tables, that relate via a one-to-many relationship i.e tableOne (1)----------(*) tableTwo
I have a standard many-to-many relationship in my database between Person and Widget. A
I have a pretty standard setup, with a many-to-many relationship between Departments and Employees.
I have a standard many-to-one relationship set up. There are a bunch of fields,
I have a 3-table schema. Two of the tables (Trade/Portfolio) have a 1:1 relationship,
Currently I have two tables in my database Encounters and Referrals : There is
I have 2 related MySQL tables in a one to many relationship. Customers: cust_id,

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.