Results 1 to 5 of 5
  1. #1
    jamal numan is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jan 2011
    Location
    Ramallah, West Bank
    Posts
    113

    Question How to combine two tables in one table such that values are neither duplicated nor mi

    How to combine two tables in one table such that values are neither duplicated nor missed?

    please, see the attached screen shot that show my question




    i wanted to join Table5 and table6 such that the values of Field1 are all populated in the resulted table but neither duplicated nor overlapped!

    How can i perform this kind of combination?

    thank you in advance,

    regards

    Jamal

  2. #2
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    There may be a simpler way, but try this:

    Create a new query
    1. Select Field1 from Table5.
    2. Got to View -> SQL View.
    You should see something like:
    Code:
     
       Select Field1
       FROM Table5;
    3. Change the SQL in the same SQL pane so it looks like this:
    Code:
     
       Select [Table5].[Field1]
       FROM Table5
       UNION
       Select [Table6].[Field1]
       FROM Table6
       ORDER BY [Table5].[Field1];
    If you run this - you will get all the field1 values - no duplicates.
    4. Save the Query and name it, for example, Query1.
    5. Create a new Query.
    6. Select - in this order: Query1, Table5 & Table6.
    7. Join Field1 of Query1 to Field1 of Table5 & Field1 of Table6.
    8. Right-click the Join lines and make the Join Properties of both option 2.
    You should see an arrow pointing towards Table5 & Table6 on the join lines [in your new Query].
    10. Select Field1 from Query1, Field2 from Table5 and Field3 from Table6.
    11. Run the Query to verify that you get the results you need.
    12. If you really need it to be a new table - convert Query1 into a MakeTable Query and run it to create your new table.

    There may be a more sophisticated [a single query] way of creating the resultset [crosstab query, perhaps??] but I do not know off hand how to do that.

    I hope this helps.
    Last edited by Robeen; 10-28-2011 at 07:43 AM. Reason: Typo.

  3. #3
    jamal numan is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jan 2011
    Location
    Ramallah, West Bank
    Posts
    113

    Thumbs up

    Quote Originally Posted by Robeen View Post
    There may be a simpler way, but try this:

    Create a new query
    1. Select Field1 from Table5.
    2. Got to View -> SQL View.
    You should see something like:
    Code:
     
       Select Field1
       FROM Table5;
    3. Change the SQL in the same SQL pane so it looks like this:
    Code:
     
       Select [Table5].[Field1]
       FROM Table5
       UNION
       Select [Table6].[Field1]
       FROM Table6
       ORDER BY [Table5].[Field1];
    If you run this - you will get all the field1 values - no duplicates.
    4. Save the Query and name it, for example, Query1.
    5. Create a new Query.
    6. Select - in this order: Query1, Table5 & Table6.
    7. Join Field1 of Query1 to Field1 of Table5 & Field1 of Table6.
    8. Right-click the Join lines and make the Join Properties of both option 2.
    You should see an arrow pointing towards Table5 & Table6 on the join lines [in your new Query].
    10. Select Field1 from Query1, Field2 from Table5 and Field3 from Table6.
    11. Run the Query to verify that you get the results you need.
    12. If you really need it to be a new table - convert Query1 into a MakeTable Query and run it to create your new table.

    There may be a more sophisticated [a single query] way of creating the resultset [crosstab query, perhaps??] but I do not know off hand how to do that.

    I hope this helps.
    Thank you for the answer. i works like a charm!

    I've here just a little question: can we add to the resulted query a new field that of the type "AutoNumber" and then to convert the query to a table?


    very much appreciated

    regards

    Jamal

  4. #4
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    One thing you CAN do is to create an Empty Table with all the fields that your query will have - and then add an AutoNumber field to the empty Table.

    Now - instead of making your query a MakeTable Query - you can make it an append query.
    When you run the append query - it will add all your rows of data to the empty table and Access will automatically put incremental numbers in the AutoNumber.

    Will that work for you?

    If you HAVE to create a new table each time - I'm not sure how you would put the autonumber field into the make table query. But there might be a way in Access. I just don't know it.

  5. #5
    jamal numan is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jan 2011
    Location
    Ramallah, West Bank
    Posts
    113

    Thumbs up

    Quote Originally Posted by Robeen View Post
    One thing you CAN do is to create an Empty Table with all the fields that your query will have - and then add an AutoNumber field to the empty Table.

    Now - instead of making your query a MakeTable Query - you can make it an append query.
    When you run the append query - it will add all your rows of data to the empty table and Access will automatically put incremental numbers in the AutoNumber.

    Will that work for you?

    If you HAVE to create a new table each time - I'm not sure how you would put the autonumber field into the make table query. But there might be a way in Access. I just don't know it.

    Thank you Robeen for the answer. these notes are quite helpful.

    regards

    Jamal

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

Similar Threads

  1. Replies: 7
    Last Post: 08-18-2011, 02:18 PM
  2. Combine data from 3 different tables
    By udigold1 in forum Queries
    Replies: 3
    Last Post: 06-29-2011, 12:18 AM
  3. Combine values from multiple fields
    By jsimard in forum Queries
    Replies: 8
    Last Post: 06-09-2011, 01:05 PM
  4. Combine the values of two fields on a form
    By nyteowl in forum Access
    Replies: 4
    Last Post: 10-15-2010, 11:16 AM
  5. I have 4 Tables in Access - can I combine them?
    By officespace in forum Access
    Replies: 6
    Last Post: 02-22-2009, 07:21 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