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

Several many-to-many relationships to one table

My database has several categories to which I want to attach user-authored text "notes". For instance, an entry in a high level table named jobs may have several notes written by the user about it, but so might a lower level entry in sub_projects.…
Luciasar
  • 393
  • 3
  • 7
  • 21
0
votes
1 answer

How to add an entry to ManyToManyField in Django?

I have the following models: class Vote(models.Model): cmt = models.ForeignKey(Comment) user = models.ForeignKey(User) vote_type = models.SmallIntegerField(default=0) # vote_type is +1 for upvote & -1 for downvote class…
0
votes
1 answer

Populate a column in a junction table Transact-SQL

I have two tables with a many-to-many relationship. The relevant part of the tables look like this: Filmlager [ProgramID, Type] Genre [GenreID, GenreTitle] Since there's a many-to-many relationship I've created a junction table looking like…
Emil Kling
  • 35
  • 6
0
votes
1 answer

Select rows that have a specific set of items associated with them through a junction table

Suppose we have the following schema: CREATE TABLE customers( id INTEGER PRIMARY KEY, name TEXT ); CREATE TABLE items( id INTEGER PRIMARY KEY, name TEXT ); CREATE TABLE customers_items( customerid INTEGER, itemid INTEGER,…
user1205255
  • 139
  • 1
  • 6
0
votes
1 answer

Updating a junction table with data that is present in the other tables

I have these two tables public partial class Items { public Items() { this.Variables = new HashSet(); } public int Id { get; set; } public string name {get; set}; //other columns public virtual…
tscLegend
  • 76
  • 11
0
votes
1 answer

SQL Junction Query - How To Get Exact Match

I would like the answer to this question to be DBMS agnostic, but if it is relevant I am using Access SQL. Please keep note that this is a simplified version of what I am trying to do. Now, consider I have the following three tables. My main fruits…
Elias
  • 2,602
  • 5
  • 28
  • 57
0
votes
1 answer

Access database design - Normalizing out two separate (and related) fields

I've created a database to store information for Design work my company does. The main table currently has a lot of Null fields in it, because there are numerous "optional" fields.... a prime candidate for normalization, as I understand it! My…
0
votes
3 answers

Querying all data from a table joining ONLY the latest record from a junction table

I'm working with a database structure similar to this one: http://dev.mysql.com/doc/employee/en/sakila-structure.html Table: employees Table with information about each employee. +---------+----------+ | emp_no* | emp_name | +---------+----------+ |…
rtribaldos
  • 1,177
  • 14
  • 28
0
votes
2 answers

Foreign key to reference all records or no records in junction table

This seems like a desirable feature but I can't seem to figure out how I would do it while the foreign key is a part of the primary key (composite key). The table is a simple junction table for a many to many relationship referencing User.id and…
0
votes
1 answer

Modify the response of a SQL query involving junction table

I have two tables linked in a junction table like this : REATE TABLE eventsUsers ( eventId INT REFERENCES events (eventId), userId INT REFERENCES users (userId), PRIMARY KEY (eventId, userId) ); I want to return all the events with…
Simon
  • 6,025
  • 7
  • 46
  • 98
0
votes
1 answer

Appropriate use of surrogate key?

Say a particular country has many sights (monuments, parks, museums), and of course a particular sight can exist in many states. In terms of a logical ERD model, a junction table should be used between the M:N relationship. However, would it suffice…
0
votes
2 answers

MySQL many-to-many: Insert into table and then into junction table?

I have 3 tables: persons, places and person_place. Each person can have many favorite places, just as each place can be "favorited" by many persons/people. CREATE TABLE persons ( ID int NOT NULL AUTO_INCREMENT, name VARCHAR(50) NOT NULL //some…
MagisterMundus
  • 335
  • 4
  • 18
0
votes
1 answer

Php Yii relations with junction table

In one of my views in my project I need to display table that uses data from two tables, but one of them is juction table. I have two tables User and Skill. Relation between these two is Many-to-Many so I created junction table StudentSkills. This…
Nugy
  • 29
  • 1
  • 4
0
votes
1 answer

Using LINQ to get Max Count in Junction Table

I have gone through a lot of questions on Stackoverflow and I'm afraid that I still can't find an answer for this. I am using Entity Framework. Using LINQ I am trying to find the most popular class session in the last seven days. I have Four tables…
CByrne
  • 3
  • 1
0
votes
1 answer

Intersection of queries using junction table

I googled but could not find a suitable response. I have two tables - Students ( studentid int, studentname text ); Classroom ( classroomid int ); I created a junction table that looks like- Junction ( studentid int, classroomid…