+ Reply to Thread
Results 1 to 8 of 8

Query 2 Tables

  1. #1
    Registered User
    Join Date
    03-16-2006
    Posts
    81

    Query 2 Tables

    I have tried a few things and have now come to the point where i don't know what i'm doing

    I have 2 matching tables, both have the same columns/structure, but different data in those columns.
    What i want to do is create a query that returns the count of the same column in each table and list the results organised by the date.

    How can this be done?

    For example:

    Date--------| Column Table 1 | Column Table 2

    01/01/2011--------10-----------------20
    02/01/2011--------15-----------------10


    Thanks

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: Query 2 Tables

    Hi kingdt,

    I think I'd put a column in each table that shows which table it is from and the make a single table from the two and do a Pivot Table on them. See if the attached explains it with an example. The problem is you may have a date in table 1 that isn't in table 2 or vice versa. This makes a single table using Pivots more better. (bad english)

    BTW - you should update your profile so we can see which version of excel you are using. This would allow me to attach the correct format of file (.xls or .xlsx).
    Attached Files Attached Files
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Registered User
    Join Date
    03-16-2006
    Posts
    81

    Re: Query 2 Tables

    Thanks for the reply, I see what you mean. Another way i just realised it to create 2 queries, one for each table, and then another query using those 2 queries pulling in the data i want. Bit messy, must be a cleaner way.

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,937

    Re: Query 2 Tables

    If you are doing this in Access, then a simple aggregate query where you group on the date and count on the data.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  5. #5
    Registered User
    Join Date
    03-16-2006
    Posts
    81

    Re: Query 2 Tables

    Hi alansidman. I tried that. I linked the dates of the two tables, used the date from one of the tables and grouped on that, and then did a count on the two columns from each of the tables, but that multiplies the results.
    Last edited by kingdt; 12-13-2011 at 06:19 PM.

  6. #6
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,937

    Re: Query 2 Tables

    mmmm. I'm thinking you were right when you said you may have to create two queries. Make them aggregate queries. Then try and join the two queries into a third query. Do both tables have the same dates? Or will some dates appear in one table and not in the other?

  7. #7
    Registered User
    Join Date
    03-16-2006
    Posts
    81

    Re: Query 2 Tables

    Both have the same dates. Built another couple of simple tables and tried to do the same, but same result. If i have to do three queries then so be it, but there must be a way, maybe SQL???

  8. #8
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,937

    Re: Query 2 Tables

    Upload a copy of your simple data base and let us give it a shot. There are some really talented people here on this forum. Let them have a shot at a real situation.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1