Solved

Access left join query

Posted on 2016-10-20
5
41 Views
Last Modified: 2016-10-20
Hello,

I have a query that was written in SQL.  I need to bring the query into Access and am having a lot of trouble with the left joins.  I'm getting a lot of errors saying missing expression, etc...  Could some one help me convert this to something Access understands?
---------------------------------
SELECT M.MIL_CODE

FROM
             QUOTE          Q

  INNER JOIN QUOTE_ITEM     QI  ON QI.QUOTE_ID        = Q.QUOTE_ID
                                    AND QI.QUOTE_VERS_STOP = Q.QUOTE_VERS

  INNER JOIN BOM_PIECE      BP  ON QI.QUOTE_ITEM_ID  = BP.QUOTE_ITEM_ID

  INNER JOIN EXTN           EX  ON BP.EXTN_LIB_ID    = EX.EXTN_LIB_ID
                                     AND BP.EXTN_ID        = EX.EXTN_ID

  INNER JOIN CLASSIFICATION CL  ON EX.CLASSIF_LIB_ID = CL.CLASSIF_LIB_ID
                               AND EX.CLASSIF_ID     = CL.CLASSIF_ID

  LEFT JOIN BOM_MIL         BM  ON BM.QUOTE_ITEM_ID  = BP.QUOTE_ITEM_ID
                                     AND BM.INSTANCE_IDENT = BP.INSTANCE_IDENT
                               AND BM.OBJ_ID         = BP.OBJ_ID

  LEFT JOIN MILLING         M   ON M.MIL_LIB_ID      = BM.MIL_LIB_ID
                                     AND M.MIL_ID          = BM.MIL_ID
---------------------------------

Thanks,
Joel
0
Comment
Question by:Genius123
  • 2
  • 2
5 Comments
 
LVL 35

Expert Comment

by:PatHartman
ID: 41852727
Access uses an arcane syntax with lots of parentheses for joins.  The simplest solution if you are not familiar with it is to copy the select part of the query and then only copy the table names part of the FROM clause.  Then in QBE view, draw the joins and let Access generate the SQL for you.
0
 

Author Comment

by:Genius123
ID: 41852747
I tried that.  When I draw the left joins, I get this error.  I've tried making queries of queries and am just having a hard time with it....

left-join.pdf
0
 
LVL 35

Accepted Solution

by:
PatHartman earned 500 total points
ID: 41852760
The error message actually tells you how to solve the problem.

The way that joins work, you cannot have an inner join to the right of an outer join.

If you cannot rearrange the tables to conform to the rule, pluck out the two tables joined with a left join and put them in a separate query.  In the original query, replace the two tables with the new query.
0
 
LVL 19
ID: 41852879
you also have joins to dbo_BOM_MIL from 2 places. Perhaps a query with what you need from BOM_PIECE and BOM_MIL?

if relationships had referential integrity, the join line ends would be labeled with "1" or the infinity sign
0
 

Author Closing Comment

by:Genius123
ID: 41853103
thanks, that worked.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question