Questions tagged [junction-table]

A junction table is a table that contains common fields from two or more tables and is the canonical way to implement Many-to-Many relations in SQL and Relational-type databases.

In database management systems following the relational model, a junction table is a table that contains common fields from two or more tables. It is on the many side of a one-to-many relationship with each of the other tables. Junction tables are known under many names such as bridge table and linking table.

221 questions
4
votes
2 answers

Use 1 junction table with 3 foreign keys Or 2 junction tables with shared sequencing?

I have 3 tables that I am trying to properly create relationships between: game phase game event (a step in a 'game phase') action window (a radically different kind of step in a 'game phase') A 'game phase' can have one or more 'game event(s)',…
Glyph
  • 526
  • 5
  • 20
4
votes
1 answer

What is the necessity of junction tables?

I have implemented the following ways of storing relational topology: 1.A general junction relation table: Table: Relation Columns: id parent_type parent_id parent_prop child_type child_id child_prop On which joins are not generally capable of…
MetaChrome
  • 3,210
  • 6
  • 31
  • 48
4
votes
1 answer

Why do you need a junction table to implement a many-to-many relationship?

This has been bugging me, maybe someone can help clarify. Say I have books, and authors: one book can be written by many authors, and an author can write many books. Why couldn't I capture this with the following schema? Why do I need a junction…
sbenderli
  • 3,654
  • 9
  • 35
  • 48
3
votes
4 answers

Use SQLite SELECT to combine joined table column into one row for each category using a junction table

I am using SQLite and have three tables (there is more data in these tables - abbreviated here): Categories - Holds item categories (id, name, description) Items - (id, name, status) Reference (id, cat_id, item_id) Categories can have many items…
Vento
  • 33
  • 3
3
votes
1 answer

How to create a junction query, that returns a value from the junction itself?

I am trying to query a character with his stats, the problem is that the junction table holds the value of the stat. For example, the character is Fred, the stat is agility, and the value is 10. Meaning Fred has the stat of agility, and his value at…
Ivan Šimović
  • 497
  • 4
  • 17
3
votes
1 answer

postgresql left join multiple conditions

I am still a NB to PostgreSQL - can anyone help with this query: select distinct j.id, tt.title, m_scopus.provider_id from journal j join temporal_title "tt" on (j.id = tt.journal_id and tt.list_index = 0) left join journal_metrics…
pmelch
  • 101
  • 1
  • 3
  • 9
3
votes
1 answer

How to update the junction table with user's role in Adonis

I have a database with three tables: users, games and game_user. usersand games have a many to many relationship with game_user as its junction table The table game_user has only three columns (other than id): game_id, user_id and game_admin. The…
3
votes
1 answer

Representing a Junction Table in Entity Framework

I am creating a schema where the following logic applies: A String can belong to multiple locations. Multiple Locations can have multiple String, or no String. The DateTime (As DateScraped) at which the relationship between Location and String was…
Bitz
  • 1,128
  • 11
  • 33
3
votes
2 answers

MySQL efficient data to junction table query

The problem: I want to move the links of the categories from the table companies_1 into the company_categories table. The company_id in the company_categories table need to be equal to the id of the companies_2 table. The records of the companies_1…
Justin La France
  • 789
  • 8
  • 21
3
votes
1 answer

MS SQL: What is more efficient? Using a junction table or storing everything in a varchar?

here is a simple question to which I would like an answer to: We have a member table. Each member practices one, many or no sports. Initially we (the developers) created a [member] table, a [sports] table and a [member_sports] table, just as we have…
3
votes
1 answer

Storing gene expression data in MySQL -- junction tables needed?

I have several m x n matrices of gene expression data that I want to store in MySQL. m is approx 30,000 genes (uniquely identifiable) n is approx 3,000 samples (mostly uniquely identifiable) I'm not sure what the best way is to store these data. I…
user2223056
3
votes
2 answers

NHibernate - Many to Many Query using Junction/Joiner Table

I've found very similar questions here but none that match exactly what I'm looking for. The two closest threads I've found are (yes, they are different threads): NHibernate many-to-many criteria (1) NHibernate many-to-many criteria (2) However, I…
jchensor
  • 107
  • 1
  • 7
3
votes
2 answers

Database design to enable Multiple tags like Stackoverflow?

I have the following tables. Articles table a_id INT primary unique name VARCHAR Description VARCHAR c_id INT Category table id INT cat_name VARCHAR For now I simply use SELECT a_id,name,Description,cat_name FROM Articles LEFT JOIN…
3
votes
2 answers

SQL query on multiple tables, one being a junction table

I have a fairly simple database consisting of 4 tables: Table 1: USERS Columns: userID, user_name Table 2: GROUPS Columns: groupID, group_name Table 3 (Junction Table): GROUP_MATRIX Columns: userID, groupID Table 4: Messages Columns:…
Axl
  • 427
  • 2
  • 7
  • 19
3
votes
2 answers

Apex - SalesForce - Accessing a Parent object field through Junction object

Hello Folks, I am working on customizing some functionality on the Force.com platform. I have a question for you; I am not too sure if this is possible! What I have? : 2 custom objects - abc and pqr. Abc is the junction object between the Standard…
subodhbahl
  • 415
  • 9
  • 22
1
2
3
14 15