Skip to main content

Search

Search

Database connection join tables with two keys?

Comments

3 comments

  • Avatar
    Peter Thane

    Why would you need more than 1 join between the same 2 tables?

    If there are multiple PartNum and Customer combinations and you only want one particular selected PartNum, for example, you could add a Filter that is similar to the 2nd line of your join.

    0
  • Avatar
    Scott Mason

    You only need one join but we need multiple criteria for that join especially when the primary key on one table is a composite of two (or more) fields.

    The CustXPrt table could have the same part number but for two different companies. The combination of company + part number forms the primary key to look up records. 

    I end up writing a custom SQL query. Seems like the GUI is limited in that it can only join on one item. 

    SELECT 
    p.PartNum, p.PartDescription, cxp.XPartNum, cxp.PartDescription

    FROM [dbo].Part AS p

    INNER JOIN [dbo].CustXPrt AS cxp
    ON (p.Company = cxp.Company AND
    p.PartNum = cxp.PartNum)

    WHERE
    AND p.Company = '?Company'
    AND p.PartNum = '?SDPart'

    How would you do that inner join with the GUI? I'm not sure it's possible even though that's a fairly common database table setup scenario.

    0
  • Avatar
    Peter Thane

    I would just create a single join (company to company) but then create two Filters/Queries, one to enter the company number and the other for the part number and I believe that should work

    0

Please sign in to leave a comment.