Solved

Join expression not supported when using LEFT JOIN

Posted on 2015-02-02
4
289 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 119

Accepted Solution

by:
Rey Obrero earned 250 total points
Comment Utility
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:SimonAdept
Comment Utility
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
Comment Utility
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:SimonAdept
SimonAdept earned 250 total points
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

763 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

6 Experts available now in Live!

Get 1:1 Help Now