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

How to build query to retrieve columns from multiple tables by date

lilp32
43
I am relatively new to Access (using 2010) and this seems like it should be simple yet I can't seem to figure it out.

I have aggregate count data from 30+ counting devices (101, 102, etc) which means I have one table for each device with three columns (Date, Count, Average). I want to create a query that will show the date in one column and the count from each device in separate columns (Date, Count.101, Count.102, etc). The date ranges for each unit are not the same. I can create queries for a few devices but when I get up to all 30 it just times out. There must be an easier way to do this! Any help would be much appreciated, thanks!

Here is an example of the SQL code:

Expand|Select|Wrap|Line Numbers
  1. SELECT Date2.Date, [101].Count, [102].Count, [103].Count, [104].Count, [105].Count, [106].Count, [107].Count, [108].Count, [109].Count, [110].Count, [111].Count, [112].Count, [113].Count, [114].Count, [115].Count, [116].Count, [117].Count, [118].Count, [120].Count, [121].Count, [122].Count, [123].Count, [124].Count, [125].Count, [126].Count, [127].Count, [128].Count INTO All3
  2. FROM ((((((((((((((((((((((((((Date2 LEFT JOIN 109 ON Date2.Date = [109].Date) LEFT JOIN 105 ON Date2.Date = [105].Date) LEFT JOIN 106 ON Date2.Date = [106].Date) LEFT JOIN 108 ON Date2.Date = [108].Date) LEFT JOIN 107 ON Date2.Date = [107].Date) LEFT JOIN 104 ON Date2.Date = [104].Date) LEFT JOIN 103 ON Date2.Date = [103].Date) LEFT JOIN 102 ON Date2.Date = [102].Date) LEFT JOIN 101 ON Date2.Date = [101].Date) LEFT JOIN 110 ON Date2.Date = [110].Date) LEFT JOIN 111 ON Date2.Date = [111].Date) LEFT JOIN 112 ON Date2.Date = [112].Date) LEFT JOIN 113 ON Date2.Date = [113].Date) LEFT JOIN 114 ON Date2.Date = [114].Date) LEFT JOIN 115 ON Date2.Date = [115].Date) LEFT JOIN 116 ON Date2.Date = [116].Date) LEFT JOIN 117 ON Date2.Date = [117].Date) LEFT JOIN 118 ON [113].Date = [118].Date) LEFT JOIN 121 ON Date2.Date = [121].Date) LEFT JOIN 122 ON Date2.Date = [122].Date) LEFT JOIN 125 ON Date2.Date = [125].Date) LEFT JOIN 123 ON Date2.Date = [123].Date) LEFT JOIN 124 ON Date2.Date = [124].Date) LEFT JOIN 126 ON Date2.Date = [126].Date) LEFT JOIN 127 ON Date2.Date = [127].Date) LEFT JOIN 128 ON Date2.Date = [128].Date) LEFT JOIN 120 ON Date2.Date = [120].Date
  3. ORDER BY Date2.Date;
Oct 1 '10 #1
9 1829
nico5038
3,080 Expert 2GB
Hi Lisa,

I would start with normalizing the table design.
When you add a DeviceID (autonumber) to a table, all devices can be placed in one table.

Having such a table will allow you to use a crosstable query to get the needed overview.

Getting the idea ?

Nic;o)
Oct 1 '10 #2
lilp32
43
Thanks, I am not sure I understand - or maybe I wasn't clear before. Each table has ~90 days of data so adding Device ID just adds an ID for each day.
Oct 1 '10 #3
nico5038
3,080 Expert 2GB
The idea is to have one table like:

tblDevice with the fields:
DeviceID (autonumber)
DeviceName (e.g. your 101, 102, etc.)
DeviceDate (don't use "Date" as that's a reserved word!)
Count

The average can be calculated, thus doesn't need to be stored.

When you use an append query for each "Device table" and add the DeviceName, the result will be one table with all Device data.

Clearer?

Nic;o)
Oct 1 '10 #4
lilp32
43
Thanks for your help. I created the tblDevice but am still lost about how to do the queries.
Oct 1 '10 #5
nico5038
3,080 Expert 2GB
1) Select the tblDevice101 for a new query and set the query type to "Append" and select in the prompt the new table.
2) Place the Date and Count (hmm better call it DeviceCount as Count is also a reserved word)
3) Add a literal as field like:
DeviceName:101 and set the target fields as needed.
4) Execute the query
5) Change table to the tblDevice102 and literal field value into 102 and execute the query,
6) Etc. for 103 till end.

Getting the idea?

Nic;o)
Oct 1 '10 #6
lilp32
43
OK, that helps me get everything in one table but I really want to have one date value and counts for each date. This creates many duplicate dates. I want to be able to look at a day and see what the count is for that day on all devices. Is there some way to create a crosstab query that will do this?
Oct 1 '10 #7
nico5038
3,080 Expert 2GB
That's where the crosstable query is for.

Select the tblDevice for a new query and select the type "crosstable" and place the fields:
DeviceName (Column) (GroupBy)
DeviceDate (Header) (GroupBy)
DeviceCount (Value) (Max)

The first () indicates the setting for the extra line you get when selecting the "crosstable"

Nic;o)
Oct 1 '10 #8
lilp32
43
Thanks very much, I did get it to work!
Oct 8 '10 #9
nico5038
3,080 Expert 2GB
Glad I could help, success with your application !

Nic;o)
Oct 8 '10 #10

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

Similar topics

2
by: Beyonder | last post by:
I have five tables in my database, there are actually NO common fields between them, not even a KEY or ID or anything like that, except for the "body" of a blob field. and that text is not...
3
by: Marcel | last post by:
I'm running MySQL version 4.1.7-nt. When I submit the following query: SELECT DISTINCT pet from pets; I get: dog cat lama
1
by: Raj | last post by:
Hi I am trying to populate datagrid with a query which has multiple tables on it. It loads data fine but when I try to apply tablestylegrid and columnstyles its not taking it. Can anybody...
3
by: Brett | last post by:
The first query will run but the second will not: Dim constring As String Dim id As String = "10-03" File.Delete(FilePath & CSVFileName) constring = ("Provider=Microsoft.Jet.OLEDB.4.0;Data...
5
by: mimo | last post by:
Hello, I have seen samples on how to pull data from one table and save back to it using the Form View control. How do I pull from multiple tables and save back to multiple tables on one...
4
by: Tess2819 | last post by:
Hi Everyone, This is my first topic so I hope you can help. I have searched but can't seem to find what I am looking for, so here it is. I want to create a query using design view in...
10
by: VirtualLilac | last post by:
Hi, Am trying to build a database for non-profit organisation, its a volunteer job and nobody around to guide me. From my learning I could able to build few reports and forms but am feeling stuck...
3
by: sknapman | last post by:
Hi, im using access and want to filter some results so the first 2 hours get flagged as one category and everything over 2 hours a different category. Ive got a field returning the hours, so i...
0
by: SamKhazary | last post by:
I have created a database that has a main table with a description of different products. I have 5 other data bases that are linked sheets that have returns for the 5 different prduct groups. I'd...
3
by: dponce | last post by:
Hello, I need some help, this is what I am trying to accomplish. I have 14 different tables, all the tables have the same colums but different information is recorded in each one. What I am trying...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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
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...

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.