473,386 Members | 1,830 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,386 software developers and data experts.

Combining two queries

I've got a question/request for the SQL gurus.
I'm building a model of bandwidth demand in MS Access and want to get
aggregated results for demand at each PCP in each time period.

The two queries below are used to count the number of households of each
Socio-Economic Type (each postcode has been allocated an SE-Type), and use
that to count the number of connections requiring a bandwidth less than 512
that will be required at the PCP in each month, and to put the results into
a table called PCP-Demands.

Unfortunately, my SQLing skills are somewhat limited, and I couldn't figure
out how to do this as a single query, so have had to put results into a temp
table, then pull them out again into my results table. It works, but
obviously it takes longer to run - I currently have a machine beside me that
has been grinding away since yesterday afternoon, and I don't expect to
finish today.

So, what I'm looking for is a way to combine the two queries below into one
query.
I'm sure it should be easy, but it's got me beat. If anyone could see their
way clear to combine these two queries for me, I'd be most appreciative.

Cheers,
Bruce.

Query to make temp table:
====================
SELECT SED.Date, PC.PCP, SUM(pc.HouseHolds * SED.[% <512]) AS Connections
INTO TempConnectionCount
FROM ([SE-Demands] AS SED INNER JOIN [PostCodes Test] AS PC
ON PC.[SE-Type]=SED.[SE-Type])
GROUP BY [SED].Date, PC.PCP;
====================

Query to put temp results into final table
====================
UPDATE [PCP-Demands], TempConnectionCount
SET [PCP-Demands].[Count <512] = TempConnectionCount.Connections
WHERE TempConnectionCount.[Date] = [PCP-Demands].[Date]
AND TempConnectionCount.[PCP] = [PCP-Demands].[PCP];
====================

As a follow up, the closest I've managed to get so far is:

Attempt to combine the two queries
====================
UPDATE [PCP-Demands], [SE-Demands], [PostCodes Test] SET
[PCP-Demands].[Count <512] = (
SELECT SUM([PostCodes Test].HouseHolds*[SE-Demands].[% <512])

FROM ([SE-Demands] INNER JOIN [PostCodes Test] ON [PostCodes
Test].[SE-Type]=[SE-Demands].[SE-Type])
)
WHERE [SE-Demands].Date=[PCP-Demands].[Date]
And [PostCodes Test].PCP=[PCP-Demands].[PCP];

=========================
which comes up with the error "Operation must use an updateable query"
Suggestions really would be appreciated!
Nov 12 '05 #1
1 5985
On Thu, 6 Nov 2003 11:32:36 +0000 (UTC), "Bruce MacDonald"
<no***@noone.com> wrote:

I don't think there is a better solution. I use the same method you
are. I agree Access is a bit stupid that it can't see I don't want to
modify data on the Group By side of the query (which legitimally is
not-updateable).
To optimize for speed, you may need an index on
TempConnectionCount.[Date] and TempConnectionCount.PCP.

-Tom.

I've got a question/request for the SQL gurus.
I'm building a model of bandwidth demand in MS Access and want to get
aggregated results for demand at each PCP in each time period.

The two queries below are used to count the number of households of each
Socio-Economic Type (each postcode has been allocated an SE-Type), and use
that to count the number of connections requiring a bandwidth less than 512
that will be required at the PCP in each month, and to put the results into
a table called PCP-Demands.

Unfortunately, my SQLing skills are somewhat limited, and I couldn't figure
out how to do this as a single query, so have had to put results into a temp
table, then pull them out again into my results table. It works, but
obviously it takes longer to run - I currently have a machine beside me that
has been grinding away since yesterday afternoon, and I don't expect to
finish today.

So, what I'm looking for is a way to combine the two queries below into one
query.
I'm sure it should be easy, but it's got me beat. If anyone could see their
way clear to combine these two queries for me, I'd be most appreciative.

Cheers,
Bruce.

Query to make temp table:
====================
SELECT SED.Date, PC.PCP, SUM(pc.HouseHolds * SED.[% <512]) AS Connections
INTO TempConnectionCount
FROM ([SE-Demands] AS SED INNER JOIN [PostCodes Test] AS PC
ON PC.[SE-Type]=SED.[SE-Type])
GROUP BY [SED].Date, PC.PCP;
====================

Query to put temp results into final table
====================
UPDATE [PCP-Demands], TempConnectionCount
SET [PCP-Demands].[Count <512] = TempConnectionCount.Connections
WHERE TempConnectionCount.[Date] = [PCP-Demands].[Date]
AND TempConnectionCount.[PCP] = [PCP-Demands].[PCP];
====================

As a follow up, the closest I've managed to get so far is:

Attempt to combine the two queries
====================
UPDATE [PCP-Demands], [SE-Demands], [PostCodes Test] SET
[PCP-Demands].[Count <512] = (
SELECT SUM([PostCodes Test].HouseHolds*[SE-Demands].[% <512])

FROM ([SE-Demands] INNER JOIN [PostCodes Test] ON [PostCodes
Test].[SE-Type]=[SE-Demands].[SE-Type])
)
WHERE [SE-Demands].Date=[PCP-Demands].[Date]
And [PostCodes Test].PCP=[PCP-Demands].[PCP];

=========================
which comes up with the error "Operation must use an updateable query"
Suggestions really would be appreciated!


Nov 12 '05 #2

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

Similar topics

7
by: frizzle | last post by:
Hi, I know this might sound strange but i think(/hope) it's quite simple: I'm running 2 queries in a mysql DB, first one returns 20 results. Now how can i echo results from the second query...
2
by: SomeDude | last post by:
Lo group, I am wondering if there is a way of combining two SELECT statements into a single query. Here's the obligatory example to clarify things: SELECT id WHERE name=mike SELECT bills...
1
by: ravi | last post by:
I have created the following interest to calculate the interest for the following currency pairs. I have tried to combine them in macros using conditions but the next query that is run in the macro...
2
by: BeruthialsCat | last post by:
I have 4 crosstabs which are keyed on a managerID field. I want to combine them to provide the data for a graph. I currently have them combined in a union query to produce 4 rows of data for each...
1
by: ferraro.joseph | last post by:
Hi, I'm querying Salesforce.com via their AJAX toolkit and outputting query results into a table. Currently, their toolkit does not possess the ability to do table joins via their structured...
2
by: billelev | last post by:
Does anyone know if it is possible to combine two queries that have the same fields? I basically want to combine a number of fields with the totals for those fields into one query (see example...
7
by: tcveltma | last post by:
Hi again, Ok, so I have about 15 crosstab queries. Each crosstab query is an employee's name. Within the query are the weeks as the column heading, the work order numbers as the row heading, and...
19
by: Gilberto | last post by:
Hello I have created TWO different queries (for products belonging to FRONT and REAR) which use product information to filter the total (sum all belonging to the same category) of all the FRONT...
3
by: billelev | last post by:
I am trying to combine two queries into one UNION query. The first sub-query works, but the second creates the following error at the end of the first iif statement: "Syntax error in union query" ...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.