+ Reply to Thread
Results 1 to 7 of 7

Consoldate data from 3 different tables in same database

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    05-21-2014
    Location
    United States
    MS-Off Ver
    Office 365 on Windows 10
    Posts
    122

    Question Consoldate data from 3 different tables in same database

    I have a database with 3 tables. All 3 tables contain the same fields.

    One of the fields is named "Email Address" and another one of the fields is named "Source" (which in each table is the name of the table itself).

    My goal is to consolidate the 3 tables into 1 table based on a unique identifier (in this case Email Address) and identify the Sources where the same email address appears in each of the 3 tables.

    I tried using an Append query, but this did not seem to work. Can someone please help?

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

    Re: Consoldate data from 3 different tables in same database

    Use a UNION ALL Query to join all three tables into one. If you then need them to be a new table instead of just a result, then create a make table query using the Union Query as a record source.
    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

  3. #3
    Forum Contributor
    Join Date
    05-21-2014
    Location
    United States
    MS-Off Ver
    Office 365 on Windows 10
    Posts
    122

    Re: Consoldate data from 3 different tables in same database

    Thanks. This doesn't seem to quite do what I need it to do. It combined all 3 tables which is good, but it has duplicate rows based on email address.

    What I need next is to eliminate the duplicates but add an indicator showing which tables each of the duplicates appeared in. Is this possible?

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

    Re: Consoldate data from 3 different tables in same database

    if you do a Union statement without the All, it should not show duplicates. But I am a little bit confused about the part showing where the duplicates are. Are you able to mock up some sample of what you have and what you want as a result. Perhaps only a couple of records from each table and then what the result should appear like. It might make it easier to provide a workable solution. Is there one table which contains at least one record for each party and email.

    If you have your tables set up as one having all emails, then the attached file may work for you.
    Attached Files Attached Files
    Last edited by alansidman; 04-08-2015 at 06:37 PM.

  5. #5
    Forum Contributor
    Join Date
    05-21-2014
    Location
    United States
    MS-Off Ver
    Office 365 on Windows 10
    Posts
    122

    Re: Consoldate data from 3 different tables in same database

    I am attaching a sample database here.

    You will see that based on email address, there are duplicate records between table 1 and table 2 ([email protected]), table 2 and table 3 ([email protected]), and table 1 and table 3 ([email protected]).

    But you can see that the value in the field named "Source" is different.

    What I need to do is combine the 3 tables, remove the duplicates so that there is only one line per unique email address, but have an indicator showing, for example, that [email protected] is in both Table 1 and Table 2.

    Does this make sense?
    Attached Files Attached Files

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

    Re: Consoldate data from 3 different tables in same database

    I understand what you are looking for. See if the attached does what you want. I had to create several Left Join queries and then a Union Query and finally filtered the Union Query to get the results. Look it over closely and advise if this achieves what you want.
    Attached Files Attached Files
    Last edited by alansidman; 04-09-2015 at 12:31 PM.

  7. #7
    Registered User
    Join Date
    09-28-2014
    Location
    Hackney, South Australia
    MS-Off Ver
    MS Office 2003
    Posts
    15

    Re: Consoldate data from 3 different tables in same database

    Quote Originally Posted by alansidman View Post
    I understand what you are looking for. See if the attached does what you want. I had to create several Left Join queries and then a Union Query and finally filtered the Union Query to get the results. Look it over closely and advise if this achieves what you want.
    Thanks for posting your solution. I was able to consolidate my tables in the same database.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Help with Consoldate Syntax
    By ballz in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-08-2014, 04:07 PM
  2. Relational database tables
    By Tim Kennedy in forum Excel General
    Replies: 2
    Last Post: 04-21-2013, 05:08 PM
  3. using selection/range for transfering tables of data to records for database
    By nonplussed in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-22-2011, 05:42 PM
  4. Creating data tables from a database without using pivot tables
    By gareth.campbell in forum Excel General
    Replies: 4
    Last Post: 11-24-2010, 12:23 PM
  5. Macro retreiving data from SQL database through Access Linked tables and queries
    By Frederik_C in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-12-2008, 05:45 AM

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