Democratic Underground Latest Greatest Lobby Journals Search Options Help Login
Google

Are there any Microsoft Access gurus in the house?

Printer-friendly format Printer-friendly format
Printer-friendly format Email this thread to a friend
Printer-friendly format Bookmark this thread
This topic is archived.
Home » Discuss » The DU Lounge Donate to DU
 
Squatch Donating Member (1000+ posts) Send PM | Profile | Ignore Wed Aug-22-07 10:10 AM
Original message
Are there any Microsoft Access gurus in the house?
I am pretty damned new to Access and have the following problem.

I have a number of tables, each arranged thusly (sample data only):

Table 1:
ID Qty
1 9
2 8
3 14

Table 2:
ID Qty
1 5
3 3
6 3

Table 3:
ID Qty
1 4
6 1
7 2

How do I build a query so that the resultant table sums each value for each ID in each table:

Query results:
ID Qty
1 18
2 8
3 17
6 4
7 2

Any help is greatly appreciated and will earn you a free beer the next time you're in DC (if the query works, that is).

Brian
Printer Friendly | Permalink |  | Top
mainegreen Donating Member (1000+ posts) Send PM | Profile | Ignore Wed Aug-22-07 10:37 AM
Response to Original message
1. You need to do a UNION type sub query and then sum the union.
Example

SELECT ID, Qty FROM Table_1
UNION ALL
SELECT ID, Qty FROM Table_2
UNION ALL
SELECT ID, Qty FROM Table_3

This is your base query. Access can not do this in the visual design mode so you have to switch to SQL view (if you need help doing this, feel free to ask). Save this query as 'source_query' or some sensible name

Now build another query based on the query you just created. This query is a grouped query. Do this by clicking the mathmatical greek letter 'E' thing to get the Totals row in the designer. Then you should group by the ID and SUM the Qty column.

The SQL will look something like this:

Select ID, SUM(Qty) as Qty_Summed
FROM source_query
GROUP BY ID



Does this help?
Printer Friendly | Permalink |  | Top
 
Squatch Donating Member (1000+ posts) Send PM | Profile | Ignore Wed Aug-22-07 10:57 AM
Response to Reply #1
2. That makes perfect sense. Thanks a bunch!
Printer Friendly | Permalink |  | Top
 
Squatch Donating Member (1000+ posts) Send PM | Profile | Ignore Wed Aug-22-07 11:38 AM
Response to Reply #1
3. It worked like a charm.
I am working with a data set with nearly 600,000 rows of data in about 40 tables and I just needed to sum the unique ids. Thanks a bunch for your help!
Printer Friendly | Permalink |  | Top
 
Orrex Donating Member (1000+ posts) Send PM | Profile | Ignore Wed Aug-22-07 11:59 AM
Response to Reply #3
4. What you don't realize
Is that every time you run that query, you transfer $5.00 from your bank account to Mainegreen's.

It's quite clever, really.
Printer Friendly | Permalink |  | Top
 
DU AdBot (1000+ posts) Click to send private message to this author Click to view 
this author's profile Click to add 
this author to your buddy list Click to add 
this author to your Ignore list Wed Apr 17th 2024, 11:46 PM
Response to Original message
Advertisements [?]
 Top

Home » Discuss » The DU Lounge Donate to DU

Powered by DCForum+ Version 1.1 Copyright 1997-2002 DCScripts.com
Software has been extensively modified by the DU administrators


Important Notices: By participating on this discussion board, visitors agree to abide by the rules outlined on our Rules page. Messages posted on the Democratic Underground Discussion Forums are the opinions of the individuals who post them, and do not necessarily represent the opinions of Democratic Underground, LLC.

Home  |  Discussion Forums  |  Journals |  Store  |  Donate

About DU  |  Contact Us  |  Privacy Policy

Got a message for Democratic Underground? Click here to send us a message.

© 2001 - 2011 Democratic Underground, LLC