Results 1 to 4 of 4
  1. #1
    garvey is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2014
    Posts
    1

    Data in one table but not the other

    Hi,



    I have two tables (A &B) which have the same design (columns 1-10).
    Some of the data in Table B is in Table A, but I need the data in Table A, that is not in B.

    I have tried using this code, but am getting no results

    Code:
    SELECT [Table A].*
    FROM [Table A], [Table B]
    WHERE 
    ([Table A].[1]+[Table A].[2]+[Table A].[3]+[Table A].[4]+[Table A].[5])
    <>
    ([Table B].[1]+[Table B].[2]+[Table B].[3]+[Table B].[4]+[Table B].[5]);
    Can anyone help me??
    Should the tables be joined by columns 1-5?

    Thanks

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    Do an outer join. In the picture the join arrow points to the table that could be missing records. (the table with the base of arrow shows all records)
    Click image for larger version. 

Name:	outer join.png 
Views:	6 
Size:	7.9 KB 
ID:	16356
    SELECT tNames.ClientID, tCampByScout.CampID
    FROM tNames LEFT JOIN tCampByScout ON tNames.ClientID = tCampByScout.ClientID;

  3. #3
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    ranman256,

    You forgot your where condition. That will give you all the data from tNames, and any matching data in tCampbyScout, but not only the data that is in tNames that does not have matching values in tCampbyScout. You need to add a WHERE clause to zero in on just that data, i.e.
    Code:
    SELECT tNames.ClientID, tCampByScout.CampID
    FROM tNames LEFT JOIN tCampByScout ON tNames.ClientID = tCampByScout.ClientID
    WHERE tCampByScout.CampID is Null;
    By the way, Access has an Unmatched Query Wizard that can do this for you. The only thing is, it will only match on one field. However, you can edit it after it is created and add in any other Joins that you need.

  4. #4
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Garvey,

    Does this work?
    Code:
    SELECT [Table A].*
    FROM [Table A]
    LEFT JOIN [Table B]
    ON  [Table A].[1]=[Table B].[1] 
    AND [Table A].[2]=[Table B].[2] 
    AND [Table A].[3]=[Table B].[3] 
    AND [Table A].[4]=[Table B].[4] 
    AND [Table A].[5]=[Table B].[5] 
    WHERE [Table B].[1] is Null;

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

Similar Threads

  1. Replies: 5
    Last Post: 09-06-2013, 11:52 AM
  2. Replies: 2
    Last Post: 12-17-2012, 03:46 PM
  3. Replies: 13
    Last Post: 10-04-2012, 04:15 PM
  4. Replies: 4
    Last Post: 02-27-2012, 10:29 AM
  5. Replies: 4
    Last Post: 12-22-2011, 03:04 AM

Tags for this Thread

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