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
2
votes
3 answers

How can I store and index a list in a relational database?

I'm working on constructing a database (SQLite) to store information about each run of a Mathematica script I've written. The script takes several input parameters, so my DB has a table with a column for each parameter (among other columns). Some of…
David Z
  • 128,184
  • 27
  • 255
  • 279
2
votes
1 answer

Complex Database Relations (Junction Tables)

My Question is about the idea of combining two junction tables into one, for similarly related tables. Please read to see what I mean. Also note that this is indeed a problem I am faced with and therefore relevant to this forum. It is just a topic…
Chiramisu
  • 4,687
  • 7
  • 47
  • 77
2
votes
1 answer

How can I have my composite primar key in a junction table using sequelize?

I have a composite primary key in my table Foo, and a single primary key in Bar. When I make a junction using the belongsToMany syntax, only one primary key component shows up in the junction table (the first one that is beeing defined). I was…
2
votes
1 answer

Joining two tables and two junction tables

I have these tables: Games (game_id,game_name, etc) Teams (teams_id,team_name, etc) Players (players_id, player_name, etc.) junction tables: games_teams (game_id,teams_id) teams_players (teams_id, player_id) Basically for every game I want to…
kattouf
  • 59
  • 6
2
votes
1 answer

Entity Framework 4 Navigation properties missing from Data Sources

I have DB that contains 3 tables - Actors, Films, Actors_Films. 2 of the tables have a many-to-many relationship (Actors and Films), which is modelled using a junction table (Actors_Films). I'm using EF4 in a Silverlight app. I've created a EF…
MJM
  • 357
  • 1
  • 4
  • 16
2
votes
3 answers

MySQL: Select distinct values from one column if other column has two determined values in junction table

I have junction table: CREATE TABLE `book_tags` ( `id` int(11) NOT NULL, `book_id` int(11) DEFAULT NULL, `tag_id` int(11) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; with values like INSERT INTO `book_tags`…
oshka
  • 63
  • 2
  • 7
2
votes
0 answers

relation many to many with three table in UML

I have three tables : tableA, tableB and tableC. My question is: Is it possible to have many-to-many relation between these tables and create a table whose name is tableA_tableB_tableC in UML ?
alpha
  • 511
  • 8
  • 15
2
votes
1 answer

Using junction tables in PHP and MySQL to categorize and include and exclude categories

I'm trying to analyze tweets using manually assigned categories. Everything's stored in a MySQL database. I can add and remove tweets, categories, and the relationships between them without any problems. Including categories using OR logic works as…
svadhisthana
  • 163
  • 2
  • 16
2
votes
1 answer

asp.Net How to save data to junction table in controller

How can I save data to junction table from controller? public ActionResult Create(KreatorZamowienNabywca model) { db.KreatoryZamowien.Add(model.KreatorZamowien); db.Nabywcy.Add(model.Nabywca); db.SaveChanges(); } My database…
2
votes
1 answer

convert sequelize query to knex

I'm trying to understand how to do joins using a junction table for a many to many relationship. I set it up with sequelize, but for my own reasons I prefer knex. I am trying to convert a query to knex to better understand how to do these joins…
Eric Shell
  • 913
  • 2
  • 8
  • 19
2
votes
5 answers

How to design a SQL lookup table where order matters

I am trying to create a lookup table where the order of the elements matters. My lookup table has the following structure id table1id table2id 1 1 1 2 1 2 3 1 3 4 2 2 5 2 1 6 2 3 My goal is to…
Brandon
  • 187
  • 13
2
votes
2 answers

How can I create foreign keys for junction table

I have Object1 and junction table and Object2. Object2 is table that has many junction tables, but can have only one junction table torefrencing to it. When table Object1 is removed, then junction table and Object2 should be removed. How can I make…
newbie
  • 24,286
  • 80
  • 201
  • 301
2
votes
0 answers

MySQL insert into many-to-many junction table when the IDs are auto_increment

I'm trying to wrap my head around many-to-many table connections. I have three tables: Modules, Phases, and Module_Phases (junction). Both Modules and Phases have primary keys as auto_increment. create table Modules ( MID int not null…
svennand
  • 73
  • 1
  • 8
2
votes
0 answers

Filtering SQL Results with Tags in a Junction Table

I'm trying to select testIDs based off a set of tagIDs. I want to select all the tests that are tagged with all of the tags in a set of tags. For example, if I wanted all the testIDs tagged with tagFK 1 and 2, I would expect to get back only testID…
Guy
  • 876
  • 1
  • 10
  • 28
2
votes
1 answer

Android Content Provider SQLite Junction Tables

I'm implementing a Content Provider, which is backed by a fairly complex SQLite DB schema. The database has a few junction tables and I'm unsure whether they should be visible to the user of the Content Provider or not. The parent tables are exposed…
1 2
3
14 15