Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Join expression not supported when using LEFT JOIN

Posted on 2015-02-02
4
Medium Priority
?
433 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 1000 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 1000 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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
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.
Suggested Courses

963 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