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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:45:09+00:00 2026-05-10T23:45:09+00:00

Is that possible? I mean, can both ends of the many to many relationship

  • 0

Is that possible? I mean, can both ends of the many to many relationship point to the same table?

  • 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. 2026-05-10T23:45:10+00:00Added an answer on May 10, 2026 at 11:45 pm

    I’m not sure how you’d do it without enormous, horrible redundancy. The standard way to handle a many-to-many relationship between two tables is via a third table that contains two primary key values, one for the first table, one for the second table, with a unique constraint (read ‘index’) on the combination of all those columns, and possibly with one or two duplicate (non-unique) indexes on the separate primary keys. In outline:

    CREATE TABLE Table1 (pkcol1 ... PRIMARY KEY, ...); CREATE TABLE Table2 (pkcol2 ... PRIMARY KEY, ...); CREATE TABLE MtoM_Table1_Table2 (      pkcol1 ... REFERENCES Table1,      pkcol2 ... REFERENCES Table2,      PRIMARY KEY (pkcol1, pkcol2) ); -- CREATE INDEX fk1_mtom_table1_table2 ON MtoM_Table1_Table2(pkcol1); -- CREATE INDEX fk2_mtom_table1_table2 ON MtoM_Table1_Table2(pkcol2); 

    If your DBMS is intelligent, you can skip the separate index on the leading column of the primary key since the index on the primary key can also be used when searching for the just the leading value.

    Suppose Table1 and Table2 are the same table (so, in fact, we have just Table1), as in the question; this would normally still require the MtoM_Table1_Table1 mapping table – a separate table from the main table. The mapping table must have separate names for the PK (primary key) column, but both columns (or sets of columns) in the mapping table will refer to the PK column(s) in Table1.

    CREATE TABLE Table1 (pkcol1 ... PRIMARY KEY, ...); CREATE TABLE MtoM_Table1_Table1 (      pkcol1 ... REFERENCES Table1(pkcol1),      akcol1 ... REFERENCES Table1(pkcol1),      PRIMARY KEY (pkcol1, akcol1) ); -- CREATE INDEX fk1_mtom_table1_table1 ON MtoM_Table1_Table1(pkcol1); -- CREATE INDEX fk2_mtom_table1_table1 ON MtoM_Table1_Table1(akcol1); 

    If you wanted to eliminate the mapping table too, then you would have to have a second column in Table1 to hold the other PK value – call it FKcol1 (for foreign key column). This then leaves you with a quandary: what is the primary key? It has to be the combination of PKCol1 and FKCol1. But FKCol1 is supposed to reference the primary key of another row — so you have a contradiction. Even supposing you managed to avoid that as a problem (how, exactly?), to have ‘many rows’ in the referencing side of the many-to-many relationship, you must have multiple rows in the master table with the same data in all columns except FKcol, but these will reference a number (more than one, in general) other rows in the table. This is a contradiction plus a nightmare of redundancy, plus you’ve lost your simple primary key, plus it would be horrible to work out what the heck is going on.

    CREATE TABLE Table1 (     pkcol1 ... /* PRIMARY KEY */,     fkcol1 ... /* FOREIGN KEY REFERENCES Table1(pkcol1) */,     ... ); -- CREATE INDEX fk1_table1 ON Table1(pkcol1); -- CREATE INDEX fk2_table1 ON Table1(fkcol1); 

    So, I’m convinced that the only sane answer is ‘No – you cannot represent both ends of a many-to-many relationship in the same table; you must use a mapping table to retain much chance of anything working ‘as usual’ in the system’.

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

Sidebar

Ask A Question

Stats

  • Questions 74k
  • Answers 74k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer If you're stuck with C# 2.0, use an anonymous method… May 11, 2026 at 2:20 pm
  • added an answer The java.net.URI class can help; in the documentation of URL… May 11, 2026 at 2:20 pm
  • added an answer The JScript engine can be thought of as a virtual… May 11, 2026 at 2:20 pm

Related Questions

Does anyone know if it possible to define the equivalent of a java custom
I've been looking into improving SQLite performance for my site, especially with regard to
Anyone knows if is possible to have partial class definition on C++ ? Something
When designing a user interface for an application that is going to be used

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.