Results 1 to 8 of 8
  1. #1
    deepanadhi is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    22

    Unmatched Query Qizard.

    Hi,
    I have to find the records in table A which are not present in table B and display it as result. But the Problem is value in table A might not be exactly same as the values in Table B.

    For Ex : Table A - contain value 125458
    Table B might contain value same as 125458 or something like this 125458-1234 or 1234-125458 or '125458, 1234'.

    In all the above cases , it is considered that both the values are equal and this record should not be displayed in the output.



    Any help how this can be done. I dont have much knowledge about VB coding.

    Thanks,
    Deepan

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,954
    Try:
    SELECT *
    FROM TableA
    WHERE (((DLookUp("[fieldname]","[TableB]","InStr([fieldname]," & [fieldname] & ")>0")) Is Null));

    Domain aggregate functions can be very slow but I don't see how this can be done with a subquery. Alternative is VBA code looping through recordsets and either setting a field to flag the record or write record ID to a temp table.
    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
    deepanadhi is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    22
    Quote Originally Posted by June7 View Post
    Try:
    SELECT *
    FROM TableA
    WHERE (((DLookUp("[fieldname]","[TableB]","InStr([fieldname]," & [fieldname] & ")>0")) Is Null));

    Domain aggregate functions can be very slow but I don't see how this can be done with a subquery. Alternative is VBA code looping through recordsets and either setting a field to flag the record or write record ID to a temp table.
    Hi June7,

    Thanks alot for the reply. I am verymuch new to both Access & VB Coding.
    So where should this piece of code should be used. your help would be much appreciated if you can explain me in bit more detail.

    TIA,
    Deepan

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,954
    It is a query statement. Build a query. Open query designer. Either build in Design View with the grid or SQL view and type or copy/paste the statement. Replace with your table and field names where needed.
    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
    recyan's Avatar
    recyan is offline Expert
    Windows 2K Access 2000
    Join Date
    Dec 2011
    Posts
    662
    Perhaps :

    Code:
    SELECT 
    	TableA.field1
    FROM 
    	TableA
    WHERE 
    	(
    		(
    			(TableA.field1) 
    			Not In 
    			(
    				SELECT DISTINCT 
    					TableA.field1 
    				FROM 
    					TableA 
    					INNER JOIN 
    					TableB 
    					ON 
    					TableB.field2 LIKE TableA.field1 & '*'
    			)
    		)
    	);
    Thanks

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,954
    Very close recyan. I had tried something like that - the DISTINCT did not occur to me. So I then tried InStr function in subquery and got stumped. That's when I went to the DLookup.

    Your suggestion works if the TableA value will always be at the beginning of the string in TableB value. Now after seeing yours I got this mod to work:

    SELECT field FROM TableA WHERE field Not In (SELECT DISTINCT field FROM TableA INNER JOIN TableB ON TableB.field LIKE '*' & TableA.field & '*');
    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
    recyan's Avatar
    recyan is offline Expert
    Windows 2K Access 2000
    Join Date
    Dec 2011
    Posts
    662
    You are right June.
    Also perhaps assumption, that at OP's end, TableA field is always subset of TableB field.

    Thanks

  8. #8
    deepanadhi is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    22
    Quote Originally Posted by recyan View Post
    You are right June.
    Also perhaps assumption, that at OP's end, TableA field is always subset of TableB field.

    Thanks
    Thanksalot June7 & Recyan. Its working

    Thanks,
    Deepan M

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

Similar Threads

  1. Query and unmatched records
    By jlgray0127 in forum Forms
    Replies: 1
    Last Post: 03-19-2012, 05:56 PM
  2. Help! Unmatched Records Query
    By Hberg in forum Access
    Replies: 1
    Last Post: 03-09-2012, 03:41 PM
  3. Replies: 1
    Last Post: 12-08-2011, 01:52 PM
  4. Unmatched query with multiple criteria
    By brighteyes in forum Access
    Replies: 0
    Last Post: 10-26-2011, 06:37 AM
  5. Unmatched query on 1 table
    By tmcrouse in forum Access
    Replies: 7
    Last Post: 06-01-2011, 08:38 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