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
1
vote
2 answers

How to store user-created lists with SQLite?

I'm trying to make a simple app where Users can make Lists of films/books they'd like to complete. Once a List is created, they could add to a List, or reorder the items in the List. So currently I have a User table: CREATE TABLE User ( userid …
keb
  • 63
  • 4
1
vote
1 answer

Query other fields in tables referenced by FK in junction table

I have a "junction" table (recipe_ingredients) that I'm using to handle a many-to-many relationship in my database. Each field in that table is a reference to the PK of another table: recipe_id, ingredient_id, quantity_id, and measure_id. These are…
1
vote
1 answer

Many to Many association table PK as FK in other table

I have the following tables: school, teacher, school_teacher and student. school_teacher is a many-to-many junction table using an autogenerated PK and the FKs of school and teacher. A student belongs to a teacher of a particular school and a…
Mr. Mars
  • 762
  • 1
  • 9
  • 39
1
vote
1 answer

Are there times when junction tables add more complexity than necessary?

Let's say you have a recipe app. Each recipe could have ingredients, directions, and tags. Each of those could be ManyToMany with recipe. As well, directions could be ManyToMany with steps, and ingredients could be ManyToMany with amounts, and…
tdavis
  • 11
  • 1
1
vote
2 answers

Query for existence of multiple many-to-many relationships

I have what seems like a basic sql question. I have a many to many relationship through a junction table. Say Employees to Roles through EmployeeRoles Table: EMPLOYEES Columns: id, name, etc. Table: ROLES Columns: id, name Table:…
David T
  • 765
  • 6
  • 18
1
vote
1 answer

mysql - How to join junctional table to another junctional table with values from parent tables?

Didn't know how to correctly write a question in Title, but I will try to explain what I am trying to achieve. These are my parent tables: hgs_meaning hgs_word_types hgs_transliterations +----+---------+ +----+-----------+ …
1
vote
1 answer

mysql - How to display primary key from junctional table in result table after JOIN query?

I have a relational database model. Because I am learning MySQL queries for this kind of database design, I know the basics, but I got to the problem. These are my tables: hgs_word_types hgs_meanings +----+-----------+ …
Boris J.
  • 113
  • 8
1
vote
1 answer

How Can I Use JPQL Using Different Database Schemas?

In a SQL Server database I have a table mapped to JPA: @Table(name = "Demandas", catalog = "DIAGE", schema = "ade") There are three tables (DemandaExecutivo, DemandaGerente, DemandaAssessor) that are junction tables, which were automatically…
jMarcel
  • 958
  • 5
  • 24
  • 54
1
vote
1 answer

Composite primary key in junction table - Sequelize

Working with Sequelize and MySQL database, I was trying to achieve composite primary keys combination in junction table, but unfortunately without result. I have tables: They are in relation many to many. In junction table user_has_project I want…
Marcin
  • 427
  • 1
  • 6
  • 17
1
vote
1 answer

MySQL querying a junction table returns duplicate rows

I have the following table structure: So a product may have multiple product_type's. When I do my Join in MySQL I get repeated product records for each product_type. So for example if I have product called Actifoam and it has 2 records in the…
user3574492
  • 6,225
  • 9
  • 52
  • 105
1
vote
0 answers

How to search by parent and base tag in Postgresql

I have Products and Company tables that look something like this: Company: id | name ---------- 1 | Google Products id | companyId | name --------------------- 1 | 1 | Google Home 2 | 1 | Pixel Tags id | name ---------- 1 |…
1
vote
1 answer

Inputting data from a form into a junction table Microsoft Access

In access I want a single form which can input data into a junction table. The relationships are as follows. One table has plant names and basic information on the plants, another table has soil moisture content and another table has county names in…
1
vote
2 answers

Many-to-Many relationship in Access from a single table

I browsed the web but couldn't seem to find an answer to my question. I know it is possible to create a Junction table between two tables in order to create a many-to-many relationship between them, but is it also possible to create a many-to-many…
1
vote
3 answers

Yii2 Activerecord get fields from junction table and order by according to them

I have items and units table that have many to many relationship. In other words, the item has many units and the unit has many items. I managed the relation through a junction table item_units. The junction table has some extra field more than…
SaidbakR
  • 13,303
  • 20
  • 101
  • 195
1
vote
1 answer

Setting Foreign Key restraints on Junction table with a compound primary key

I have a junction table that stores the relationship between tests and the questions in the tests, with testFK and questionFK set as a compound primary key to prevent duplicate entries. Junction Table: +--------+------------+ | testFK |…
Guy
  • 876
  • 1
  • 10
  • 28