Results 1 to 6 of 6
  1. #1
    brharrii's Avatar
    brharrii is offline Advanced Beginner
    Windows XP Access 2010 64bit
    Join Date
    Jun 2012
    Location
    Seattle, WA
    Posts
    63

    Smile Adding records to a join table using a query

    I have 2 tables that are joined by a many to many table:

    tblProductInfo
    - ProductID

    tblProductLinerMM
    - PLProductID (FK to [tblProductInfo].[ProductID])
    - PLLinerID (FK to [tblLiner].[LinerID])

    tblLiner
    - LinerID


    I have a range of products that each use 2 liners. An inner liner and an outer liner. I need to add 2 records per product to the tblProductLinerMM table.


    For example:
    tblProductInfo has the following records:
    - 2138557
    - 2378954
    - 4387657

    tblLiner has 2 liners in particular that relate to these products:
    - L5475
    - L5468

    I need to create the following records in tblProductLinerMM preferably with the use of a query :
    - 2138557 | L5475
    - 2138557 | L5468
    - 2378954 | L5475
    - 2378954 | L5468
    - 4387657 | L5475
    - 4387657 | L5468


    Does anyone have any idea how I might achieve this?



    Thank you

  2. #2
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    Code:
    INSERT INTO tblProductLinerMM (PLProductId, PLLinerId)
    SELECT  ProductId,LinerId
    FROM tblLiner ,tblProductInfo ;
    Since you want all combinations, you use a Cartesian/Cross Join. There is no condition --no where clause.
    http://www.w3resource.com/sql/joins/cross-join.php

  3. #3
    brharrii's Avatar
    brharrii is offline Advanced Beginner
    Windows XP Access 2010 64bit
    Join Date
    Jun 2012
    Location
    Seattle, WA
    Posts
    63
    Awesome, thank you, If I needed to add a where condition I assume that I could? or would that change things?

  4. #4
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    In the link I posted

    The SQL CROSS JOIN produces a result set which is the number of rows in the first table multiplied by the number of rows in the second table, if no WHERE clause is used along with CROSS JOIN. This kind of result is called as Cartesian Product.

    If, WHERE clause is used with CROSS JOIN, it functions like an INNER JOIN.

  5. #5
    brharrii's Avatar
    brharrii is offline Advanced Beginner
    Windows XP Access 2010 64bit
    Join Date
    Jun 2012
    Location
    Seattle, WA
    Posts
    63
    ha, or I could just read the excellent documentation you provided to get my answer

    Thank you!

  6. #6
    brharrii's Avatar
    brharrii is offline Advanced Beginner
    Windows XP Access 2010 64bit
    Join Date
    Jun 2012
    Location
    Seattle, WA
    Posts
    63
    I'm still learning some of the terminology... I don't fully understand the difference or significance of an Inner Join versus a Cross Join. I'll do some homework though. Knowing the terms to use is the hardest part of the battle. Thank you again.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Cannot add Records; Join Key of table not...
    By turntabl1st in forum Access
    Replies: 1
    Last Post: 07-18-2012, 06:51 AM
  2. Adding records to a table from a form
    By paulofranchico in forum Forms
    Replies: 1
    Last Post: 02-07-2012, 11:30 AM
  3. VBA code for adding records to a table
    By pwalter83 in forum Forms
    Replies: 3
    Last Post: 12-21-2011, 10:52 AM
  4. Replies: 1
    Last Post: 09-20-2011, 03:23 PM
  5. Adding records to existing table
    By Mclaren in forum Programming
    Replies: 5
    Last Post: 05-18-2011, 12:44 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums