Results 1 to 8 of 8
  1. #1
    KingOf206 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Location
    Seattle
    Posts
    153

    Question How to combine 2 similar fields from 2 separate tables into 1 query ?

    I have attached an image of the example I am trying to explain.



    Ok so I already have 2 tables set up, lets call them table 1 and table 2. I have different records that have 1 Primary key that are in relationship. But I have another Field "type" (see image) that I would like to find and count up each record in the 2 tables that have the similar field and do a count so I can see the count totals from each table (of how many types there are).

    I mainly work out of design view, not very familiar with SQL. This seemed easy to do but when I began doing it I was unsuccessful.

    I hope someone can assist me with this. Again I am access intermediate-ish, so an explanation that is simply would be greatly appreciated. Looking for finish this up for a report out to work this coming friday.

    I hope the image attached helps out!!

    Click image for larger version. 

Name:	accessQ1.png 
Views:	22 
Size:	18.0 KB 
ID:	16872

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,920
    Build a UNION query then use that query in an aggregate GROUP BY (Totals) query.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    KingOf206 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Location
    Seattle
    Posts
    153
    Quote Originally Posted by June7 View Post
    Build a UNION query then use that query in an aggregate GROUP BY (Totals) query.
    When I click on "Union" it brings up an sql blank sheet. I am not sure where to go from there....?

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,920
    Have to type or copy/paste the SQL. Example UNION:

    SELECT ID, [Name], [Type], 1 AS Source FROM Table1
    ______ SELECT ID, [Name], [Type], 2 FROM Table2;


    For some odd reason, forum no longer allows me to type UNION in the example query. Put UNION in placed of the line.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    KingOf206 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Location
    Seattle
    Posts
    153
    Quote Originally Posted by June7 View Post
    Have to type or copy/paste the SQL. Example UNION:

    SELECT ID, [Name], [Type], 1 AS Source FROM Table1
    ______ SELECT ID, [Name], [Type], 2 FROM Table2;


    For some odd reason, forum no longer allows me to type UNION in the example query. Put UNION in placed of the line.



    Ok I have used that SQl code, but I dont know how to group the totals. it doesnt do the group by function at this moment. (let me know if pics would help for a better understanding) Like I said, I ma not familar with SQL code i work primaryly out of desgin view, so anything outside of that isnt as clear to me.

    More help on this would be appreciated... I am still stuck and trying to get this done by tomorrow.

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,920
    You have the UNION query correctly showing the data?

    Now use that query just like a table (except can't edit data) in another query or as the RecordSource of a report.

    Use the query builder if you want to do an aggregate query. Or build a report and use its Sorting & Grouping features with aggregate calcs in footers.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    KingOf206 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Location
    Seattle
    Posts
    153
    Quote Originally Posted by June7 View Post
    You have the UNION query correctly showing the data?

    Now use that query just like a table (except can't edit data) in another query or as the RecordSource of a report.

    Use the query builder if you want to do an aggregate query. Or build a report and use its Sorting & Grouping features with aggregate calcs in footers.


    YES it worked perfect!!!

    Thank you so much!!! #SLOVED

  8. #8
    Skincb is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Posts
    2
    first create a union query from two tables




    then with another query to count and summation type name


    SELECT ID, NOME, TIPODa Tabela 1 UNION ALL SELECT ID, NOME, TIPO DE TABLE2 ORDER BY TYPE;
    UNION.TYPE SELECIONE, Contagem (UNION.NOME) AS ContarDeNOMEFROM [UNIÃO] GROUP BY UNION.TYPE;

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Combine Similar Data From Three Queries
    By Kerberos in forum Reports
    Replies: 2
    Last Post: 05-02-2014, 11:27 AM
  2. need query to extract not similar items from two tables
    By learning_graccess in forum Queries
    Replies: 1
    Last Post: 04-02-2012, 04:52 PM
  3. Memo fields in separate tables
    By mhart in forum Database Design
    Replies: 1
    Last Post: 12-02-2011, 05:51 PM
  4. Combine two unrelated tables with the same fields
    By lghovden06 in forum Queries
    Replies: 4
    Last Post: 07-27-2010, 03:36 PM
  5. If columns are similar combine?
    By westcoastbmx in forum Queries
    Replies: 0
    Last Post: 09-04-2009, 12:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums