473,396 Members | 2,057 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,396 software developers and data experts.

How to combine Queries

Hi Folks,

I have a complex query that references a sub-query. It works fine when I
call a sub-query from the main query (using design vew), but when I try to
embed the SQL text of the sub-query into the main query I get a syntax
error...

Here's the main Query. It works fine. It references another query from the
database called "Query1a"

SELECT Benchmarks.CatID, QueryA.*, Query1a.*, QueryA.Benchmarks.BenchID,
Query1a.Benchmarks.BenchID, Benchmarks.BenchID, Benchmarks.Benchmark
FROM (Benchmarks LEFT JOIN [SELECT Benchmarks.*, GroupJobs.*,
GroupJobs.GroupID, Benchmarks.CatID, Benchmarks.BenchID
FROM Benchmarks INNER JOIN GroupJobs ON Benchmarks.BenchID =
GroupJobs.BenchID
WHERE GroupJobs.GroupID=1AND Benchmarks.CatID=40]. AS QueryA ON
Benchmarks.BenchID = QueryA.Benchmarks.BenchID) LEFT JOIN Query1a ON
Benchmarks.BenchID = Query1a.Benchmarks.BenchID
WHERE (((Benchmarks.CatID)=40) AND ((QueryA.Benchmarks.BenchID) Is Not
Null)) OR (((Query1a.Benchmarks.BenchID) Is Not Null));

Here's Query1a...
SELECT AllLatestRecords.*, OrgJobs.*, Benchmarks.CatID, Benchmarks.BenchID
FROM (OrgJobs LEFT JOIN [SELECT Max(SalaryData.Dat) AS MaxOfDat,
SalaryData.BenchID, Benchmarks.CatID, SalaryData.OrgID
FROM Benchmarks INNER JOIN (OrgJobs INNER JOIN SalaryData ON OrgJobs.BenchID
= SalaryData.BenchID) ON Benchmarks.BenchID = OrgJobs.BenchID
GROUP BY SalaryData.BenchID, Benchmarks.CatID, SalaryData.OrgID
HAVING (((Benchmarks.CatID)=40) AND ((SalaryData.OrgID)=1083)) ]. AS
AllLatestRecords ON OrgJobs.BenchID = AllLatestRecords.BenchID) INNER JOIN
Benchmarks ON OrgJobs.BenchID = Benchmarks.BenchID
WHERE (((Benchmarks.CatID)=40));

I want to combine these into one single query. I have taken the entire
second query and used the following syntax...
[ text_of_Query1a_goes_here].AS Query1a

I then try to replace the Query1a in the Main query with the above syntax
....

So in the main Query, Instead of:
"...LEFT JOIN Query1a ON ...."
I Use
"...LEFT JOIN [ text_of_Query1a_goes_here].AS Query1a ON ...."

However, This gives me a syntax error (on the field name 'orgjobs')

You'll notice that the subquery 'Query1a' also references another sub query
called 'AllLatestRecords'. This one works fine when I embed it using the
same type of syntax.

I would greatly appreciate any help with this puzzle.

Best Regards,
Jack Coletti
St. Petersburg, FL




Nov 13 '05 #1
0 1238

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Chris Lutka | last post by:
I've been racking my brains all day over this. And I'm not the best at SQL either. I need a query that will produce the following results:...
5
by: Jamie Pittman via AccessMonster.com | last post by:
I have two tables with 5000 entries on them. One is based for regular time with several variables example (employee name, date,time in and out, code, customer, building) I have another table that...
4
by: Jason Gyetko | last post by:
Is there any way to combine these two queries into one? I have tables Item_Master & Kit_Master which are the source tables. Query 2 is using both Item_Master (table) & qryKit1 (query) &...
1
by: Will | last post by:
Hi all I have a table, where there's AutoID, Name of Person (looked up from tblPerson), Name of Dispute (looked up from tblDispute), Date, Details (Memo). What I have is another table that need...
4
by: PlayHard | last post by:
I want my output in two columns like this: C_INCIDENT_TYPE \ TOTAL COUNT How do I combine my two queries to get result. First Query SELECT C_INCIDENT_TYPE, COUNT (*)
46
by: dude88888 | last post by:
Hello I have one query where i get the total number of units for an entire fund say fund 89 has 1000 total units Then i need to find out how much of the total fund each user has say user...
4
by: | last post by:
I have query1 where I set a date range. Query2 is a crosstab query and is based on query1. I don't want the queries to be saved in the mdb but I do want them to be run in VBA using a querystring. If...
1
by: csolomon | last post by:
Hello: I am using two queries to get one result set. The issue is, I return no data when I combine them into one query. I have listed both queries, as well as the 3rd query that shows them...
2
by: bips2005 | last post by:
i have got two queries, $sql1 = "select cust_id from customer where comp_name = '$compname'"; $result = $DB->query($sql1); $result->fetchInto($row); $sql = "select expirydate from...
13
by: MNNovice | last post by:
I have three tables, tblAP, tblPayroll and tblAllocation. Each records three separate expenses. All three are related by FK ECHOID, each has common fields such as AccountNo, FundNo, GrantNo,...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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.