473,503 Members | 2,082 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5995
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
2784
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
2092
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
3188
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
4137
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
2045
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
1449
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
2729
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
1810
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
1535
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
7205
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
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7287
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
7468
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...
1
5023
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1521
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
747
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
401
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.