Solved

Join expression not supported when using LEFT JOIN

Posted on 2015-02-02
4
316 Views
Last Modified: 2015-02-18
I am running the following query on table1 using MS access. The last column needs 2 LEFT JOINS on table2 and table3. If table3.boxes > 0, last column should be 1. If table3.boxes <0 or if the matching row does not exist in table3, last column should be 1.
The following query works.

SELECT Table1.DESCRIPTION, Table1.FARM, Sum(Table1.BOXES) AS QTY, Table1.DATE1 AS [DATE SOLD],Sum(TABLE1.DOLLAR) AS DOLLARS, MAX(IIf((TABLE3.[BOXES] > 0), 1,0)) AS foreca
FROM (Table1 LEFT JOIN TABLE2 ON Table1.Description = TABLE2.Name) LEFT JOIN TABLE3 ON (TABLE2.Product = TABLE3.Product and TABLE3.YEAR= 2015 and  TABLE3.WEEK=5)
GROUP BY Table1.DESCRIPTION, Table1.FARM, Table1.DATE1,
ORDER BY  Table1.DESCRIPTION

But when I replace the constants with table3 column names, it throws error "join expression not supported"

SELECT Table1.DESCRIPTION, Table1.FARM, Sum(Table1.BOXES) AS QTY, Table1.DATE1 AS [DATE SOLD],Sum(TABLE1.DOLLAR) AS DOLLARS, MAX(IIf((TABLE3.[BOXES] > 0), 1,0)) AS foreca
FROM (Table1 LEFT JOIN TABLE2 ON Table1.Description = TABLE2.Name) LEFT JOIN TABLE3 ON (TABLE2.Product = TABLE3.Product and TABLE3.YEAR= YEAR(table1.DATE1) and  TABLE3.WEEK=Weekday(table1.DATE1))
GROUP BY Table1.DESCRIPTION, Table1.FARM, Table1.DATE1,
ORDER BY  Table1.DESCRIPTION
0
Comment
Question by:Angel02
  • 2
4 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 250 total points
ID: 40585056
create query against table1, something like this

SELECT Table1.DESCRIPTION, Table1.FARM, Table1.BOXES, Table1.DATE1,TABLE1.DOLLAR, Year(Table1.DATE1) As Year1, WeekDay(Table1.DATE1) as WDay
From Table1

save the query as Q_Table1

use Q_Table1 in your query, use Year1 and WDay in the join to table3
0
 
LVL 18

Expert Comment

by:Simon
ID: 40585081
1. You're using reserved names in your table designs (Name, Year) which is not ideal
2. I'd suggest joining just table1 and table2 first, including all the columns that you need for the join to table 3, then save this query and use it as a derived table to join to table3.
0
 

Author Comment

by:Angel02
ID: 40585332
SELECT Table1.DESCRIPTION, Table1.FARM, Sum(Table1.BOXES) AS QTY, Table1.DATE1 AS [DATE SOLD],Sum(TABLE1.DOLLAR) AS DOLLARS, YEAR(Table1.DATE1) As FCYear, WEEKDAY(Table1.DATE1) As FCWeek,IIf(WEEKDAY(Table1.DATE1) between 1 and 4, 'Mo', 'Th') As FCMarket
FROM Table1
--Saved the above query as Qry_FC_Dual

SELECT FCDaily.* from (Qry_FC_Dual  AS FCDaily  LEFT JOIN table2 ON FCDaily.Description = table2.Name) LEFT JOIN table3 ON (table2.product = table3.product and table3.YEAR=FCDaily.FCYear and  table3.WEEK=FCDaily.FCWeek and table3.MARKET =FCDaily.FCMarket)

This second query still throws the same error.  Join not supported.

Also, I need to run this query from a VB application. I was hoping I could do it in one single query. Please advise.
0
 
LVL 18

Assisted Solution

by:Simon
Simon earned 250 total points
ID: 40585638
You're not joining table1 and table2 in your first saved query (Qry_FC_Dual).

> I was hoping I could do it in one single query.
Once you have got it working you can re-write it, incorporating the saved query (Qry_FC_Dual) as a subquery.

It would help if you could post a spreadsheet or small mdb with some sample data from the three tables.
0

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Stored Proc - Rewrite 42 58
UK Date format in MS Access 4 21
ERROR 3113 MODULEID NOT UPDATABLE 8 18
Access: Opening a Form to show records based on a Query 12 40
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
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 …
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

840 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