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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:33:02+00:00 2026-05-29T05:33:02+00:00

how do you construct mysql command to display data with m:n relationship? i can

  • 0

how do you construct mysql command to display data with m:n relationship?

i can use join to display a 1:n relationship, but when constructing m:n relationship, another table is created and when i try to do the same it, it only show one table plus the relationship table.

For example, I have :

table A:

  • A_id
  • A_data

table B:

  • B_id
  • B_data

table C:

  • A_A_id
  • B_B_id

I can display the table such that i have

A_id | A_data | A_A_id | B_B_id

with some data.

but the format that i want is

A_id | A_data | B_id | B_data

where A_id corresponds to B_id in table C.
I’m doing this through foreign key reference, with InnoDB engine of MySQL.

thanks

  • 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-29T05:33:02+00:00Added an answer on May 29, 2026 at 5:33 am

    If you want C to be the base table for the query (ie basically take table C and add in the corresponding _data rows), you can use:

    SELECT A.A_id, A.A_data, B.B_id, B.B_data
    FROM C
    LEFT JOIN A ON A.A_id = C.A_A_id
    LEFT JOIN B ON B.B_id = C.B_B_id
    

    This takes the table C and JOINs it to the other two tables, using C as the base table (because of the LEFT JOIN). If there are rows in C that don’t exist in A or B, you’ll just get a corresponding NULL for the _data field.

    You might want to look at the various joins (INNER, LEFT, RIGHT,…) to see what behaviour you want.

    For example you may want all ids that exist in table A to be shown, even if they aren’t in C (and just display a NULL for the corresponding B columns), etc.

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

Sidebar

Related Questions

can we add conditions in WHERE clause in MySQL with use of IF construct
Is there any good explanation of how to use MySQL's foreign key construct? I
I'm trying to construct a find command to process a bunch of files in
How can I construct a MSBuild ItemGroup to exclude .svn directories and all files
How can I construct my ajaxSend call, this seems like the place to put
How can I construct the following string in an Excel formula: Maurice "The Rocket"
I am having difficulty updating a table via PHP. Using MySQL prompt or a
I'm using MySQL and I'm trying to construct a query to do the following:
Suppose I had a MySQL table with the following column:    |variables| 1. | 'a'     | 2.
I wonder how to construct mysql DB for school diary. It will contain info

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.