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

Using SQL to join tables with a junction table

I am trying to output data from 2 different tables in my database which are joined by a junction table. Table 1: musician Columns: musicianID, surname, fName Table 2: musician_band Columns: musicianID, bandID Table 3: band Columns: bandID,…
Sam
  • 117
  • 1
  • 12
1
vote
2 answers

MS-Access Junction Table Inserts/Deletions Between Two Mutually Exclusive Lists (2 Listboxes)

With this kind of design, I would like to create a functionality with which to add and delete records from the junction table. The case is from when editing an employee and selecting what exams they can take. In the left list box would be the exams…
Nitrodist
  • 1,585
  • 5
  • 24
  • 34
1
vote
1 answer

Junction SQL Query back to First Table

I have some MS Access 2010 link tables that links back to the first table, like so: Item LinkTable [ ID ] [ ID ] [ ItemName ]-1-------*-[ FromItem ] [ ]-1-------*-[ ToItem ] Fig.1: FromItem…
RIL
  • 185
  • 2
  • 11
1
vote
3 answers

SQL Server: How can I get data from junction table that only has IDs?

I have three tables (examples here). Two with data and one that is a junction table to handle many:many relationships. Users: ID | UserName ==================== 1 | Jeremy Coulson 2 | Someone Else Repositories: ID |…
mrcoulson
  • 1,331
  • 6
  • 20
  • 35
1
vote
2 answers

Mysql working with comma separated list - Junction table

I have a Junction table with ProductID and Accessory column: TABLE1 ProductID Accessory 1 2 1 3 2 1 2 4 2 5 3 4 1 5 2 It means that for the ProductID 2, it has the…
inventor
  • 55
  • 2
  • 3
  • 10
1
vote
1 answer

Can't Constrain Both Junction Table Columns

I have a juction table that contains two foreign keys (from Profiles and Districts tables), with both columns as a composite primary key. `profID` int(11) NOT NULL, `distID` varchar(8) NOT NULL, PRIMARY KEY (`profID`,`distID`) I'd like to…
KiloVoltaire
  • 265
  • 3
  • 10
1
vote
1 answer

EF Code First Migration insists on switching junction table names

I have an EF Code First model containing a table for Foo and a table for Bar. This is a many to many relationship so EF generated a junction table called FooBars: CreateTable( "dbo.FooBar", c => new { Foo_Id =…
Bas
  • 1,946
  • 21
  • 38
1
vote
1 answer

Query to Pull Data from 2 Junction Tables

I'm creating a database for comics. Right now I have 3 main tables (comics, publishers, people) and 3 junction tables (person2comic, publisher2comic and person2publisher). I want to be able to have a search form that allows searching by any…
Midgetlegs
  • 35
  • 4
1
vote
2 answers

What the most efficient way to make a three tables JOIN with a WHERE clause in postgreSQL

I'm working with postgreSQL 9.3. I'd like to say that my question is a bit subjective but I didn't find any related questions or articles... I have three tables as following: artists: +--------+----------+ |artistId| name …
Simon
  • 6,025
  • 7
  • 46
  • 98
1
vote
2 answers

Where clause not working as expected with junction table?

I have a junction table that creates a many-to-many relationship between two other tables. Here is the diagram. Here is my base SQL query. SELECT `tag_to_url`.url_id, `websites`.url, `tags`.tag_name FROM `tag_to_url` INNER JOIN…
EternalHour
  • 8,308
  • 6
  • 38
  • 57
1
vote
1 answer

Insert values in junction table

I have three tables in database: trips(trip_id(pk), trip_name(unique), user_id(fk)) places(place_id(pk), place_name(unique)) trips_places_asc(trip_id(fk), place_id(fk)) Since, many trips can have many places, I have one junction table as…
xyz
  • 1,325
  • 5
  • 26
  • 50
1
vote
2 answers

INSERTing values into a child table referenced from parent table

I was up all last night trying to crack this but with no luck so I'm hoping you guys can help as I'm all out of ideas: I have two parent tables that I want to populate a Junction table from: Brides: create table if not exists `Brides` ( …
Bendy
  • 3,506
  • 6
  • 40
  • 71
1
vote
1 answer

MySQL Junction Table Foreign Keys

I have several tables: company, customer, company_has_customer, and transaction. company_has_customer is a many-to-many junction table using the PKs of company and customer as its PK. In almost all situations throughout the database, both the…
Kyle Johnson
  • 639
  • 7
  • 21
1
vote
1 answer

Select certain number of rows from junction table

I have 3 tables: table1: stores columns:id(PK), name, visits table2: categories columns: id(PK), name table3: cat_store columns: store_id(FK), category_id(FK) There are 27 categories and every store has at least one category. cat_store is the…
Mirceac21
  • 1,741
  • 17
  • 24
1
vote
3 answers

Is this database structure sane, correct and normalized?

So, yesterday I asked 2 questions that pivoted around the same idea: Reorganizing a database that A- wasn't normalized and B- was a mess by virtue of my ignorance. I spent the better part of the day organizing my thoughts, reading up and working…
GilloD
  • 561
  • 2
  • 6
  • 18