Results 1 to 4 of 4
  1. #1
    Charles_Access is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Oct 2013
    Posts
    2

    Join Two Tables With Duplicates

    I am trying to combine two peculiar tables in Microsoft Access and have been unable to do so even after doing a lot of brainstorming and searching on the internet. I will really appreciate if someone could help me.


    The two tables are “spend” and “export”

    Spend


    Country Metal Month Spend
    China Iron Jan 100
    China Iron Feb 200
    China Iron March 300
    India Iron Jan 400
    India Copper April 500
    Spain Zinc June 600


    Export


    Country Metal Year Export
    China Iron 2001 2,000
    India Iron 2002 4,000
    India Iron 2003 5,000
    Spain Zinc 2011 3,500
    Spain Zinc 2012 4,000
    Spain Zinc 2013 9,000



    Desired Table




    Country Metal Month Spend Year Export
    China Iron Jan 100 2001 2,000
    China Iron Feb 200
    China Iron March 300
    India Iron Jan 400 2002 4,000
    India Iron 2003 5,000
    India Copper April 500
    Spain Zinc June 600 2011 3,500
    Spain Zinc 2012 4,000
    Spain Zinc 2013 9,000

  2. #2
    Dal Jeanis is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    1) Change the name of the fields Month and Year, because they're reserved words and will cause you untold grief.

    2) Assuming these were the names of the tables and fields...
    Code:
    tblSpend
       Country
       Metal
       SpMonth
       Spend
    
    tblExport
       Country
       Metal
       ExpYear
       Export
    Then here's your query...
    Code:
    SELECT TE.Country, TE.Metal, TS.SpMonth, TS.Spend, TE.ExpYear, TE.Export    
    FROM tblSpend AS TS INNER JOIN tblExport AS TE
    ON TS.Country = TE.Country AND TS.Metal = TE.Metal;

  3. #3
    Charles_Access is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Oct 2013
    Posts
    2
    Hi Dal,

    Thanks for your reply.

    There were a few issues. When I run the query it asks me for the metal name, instead of giving me a data for all metals. And, when I entered "Iron" it gives me data for Iron but also has duplicates as shown below.

    Country Metal SpMonth Spend ExpYear Export
    China
    March 300 2001 2000
    India
    Jan 400 2003 5000
    India
    Jan 400 2002 4000
    China
    Jan 100 2001 2000
    China
    Feb 200 2001 2000

  4. #4
    Dal Jeanis is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    That means the name of the field on the table isn't properly attributed in the query. Either the name on the table is different, or the table alias is misspelled, or something like that.

    Since it's returning blanks for TE.Metal, I'd check the spelling of that one first.

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

Similar Threads

  1. Replies: 5
    Last Post: 04-25-2013, 02:38 PM
  2. Replies: 2
    Last Post: 07-12-2012, 12:46 AM
  3. Delete duplicates from both tables
    By dakpluto in forum Queries
    Replies: 2
    Last Post: 07-02-2012, 04:49 AM
  4. remove Left Join duplicates
    By lokiluke in forum Queries
    Replies: 2
    Last Post: 09-16-2011, 04:53 AM
  5. Relationship - Three Tables - No Duplicates
    By Huddle in forum Database Design
    Replies: 15
    Last Post: 07-27-2010, 07:45 AM

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