Solved

Join expression not supported when using LEFT JOIN

Posted on 2015-02-02
4
337 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Familiarize people with the process of utilizing SQL Server functions 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 Microsoft Ac…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

739 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