473,407 Members | 2,306 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

How to fix "Query too Complex" error when trying to rank using subquery?

Hi all,

I have a query called [Scan Data MAT Comparison Report] and I want to rank each customer grouped on the field [Banner] and then by descending order on [Current MAT].

I have found many solutions where I can use a subquery to do this eg:

SELECT (SELECT COUNT(*) + 1
FROM [Scan Data MAT Comparison Report] AS C
WHERE (C.Banner = CS.Banner AND C.[Current MAT] > CS.[Current MAT])) AS RankInBanner, CS.[Cust Id], CS.Banner, CS.[Current MAT]
FROM [Scan Data MAT Comparison Report] AS CS
ORDER BY CS.Banner, CS.[Current MAT] DESC;


but every time I do this I get the "Query Too Complex" error. I have tried adding and removing [] to fields and tables with no joy.
Does anyone know what SQL I should use to eliminate this error?

Thanks,
janie
Feb 8 '11 #1
1 9781
Stewart Ross
2,545 Expert Mod 2GB
Hi Janie. The 'query too complex' message occurs when the Access query engine finds that the tasks involved in processing the current and underlying queries exceed its capabilities.

It is not really the current SQL which is causing it the problem, so it can't be fixed by adding bracketing. It is the work involved in using the existing report query, [Scan Data MAT Comparison Report], as the source of both the main query and the subquery in the current SQL.

I have found that there is only one way to resolve such issues, which is to simplfy the underlying queries by either breaking them down into simpler initial queries joined later to provide the same functionality, or to create temporary tables and use the temporary table as the source for, say, a subquery.

In this case I would suggest that you create a separate named query for the inner subquery in your SQL, one whose sole task is to count the rows meeting the stated conditions. After you store the new query you can then try substituting the named query into your query/subquery combination in place of the inner reference to your reporting query.

If this fails you may need to adopt either the break it down and simplify approaches, or the temporary table approach, to make it work for you.

-Stewart

ps as the following MS support article makes clear, the issue relates to the number of joins in the underlying queries:
http://support.microsoft.com/kb/918814
Feb 8 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

33
by: Steven Bethard | last post by:
I feel like this has probably been answered before, but I couldn't find something quite like it in the archives. Feel free to point me somewhere if you know where this has already been answered. ...
3
by: David | last post by:
Hi, I'd like to adapt the query below to select records only if the Title field contains the string "Book" (as an example). I'd also like to use a different variant of the query elsewhere to...
0
by: marius | last post by:
Hi! I'm currently trying to move from MS SQLServer to MySQL, running on windows XP. When trying to connect to mysql on localhost with mysql control center I get the 2013-error "Lost connection...
5
by: Dave Smithz | last post by:
Hi there, Been working on an evolving DB program for a while now. Suddenly I have come across a situation where I need to update a table based on a group by query. For example, I have a table...
0
by: BSB | last post by:
Hi, I generate a "Find Duplicate" query for one table that will return some records I want to capture those records in my VB code..... This is my code...pls guide me how to proceed.......
3
by: DavidPr | last post by:
I've tried to incorporate an IF Statement into the below so that if the query returned nothing - a message saying "There are no jobs currently listed" would be displayed, but for some reason it...
2
by: kilo | last post by:
Hey.. I need someone hwo can help me making my sql table.. I have no php skills. I have payed for a php program that shoud make dictation for people that have some problems reading danish.. with...
3
by: prix prad | last post by:
Hi All, I encountered the above error when I tried to expand a macro as follows: #define EXPAND(array) int M_ ## array The problem occurs when we have 'array' itself as a macro: say...
4
by: James Wigginton | last post by:
Hi I have a database which archives data by financial year. I want to be able to run a query and append the data to a table which is named after the financial year, expendituresFY. The problem I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.