Solved

Access left join query

Posted on 2016-10-20
5
31 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 34

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 34

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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
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…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now