Find records in one table that doesn't exist in another (fuzzy match) (1 Viewer)

Sun_Force

Active member
Local time
Today, 22:28
Joined
Aug 29, 2020
Messages
396
This is an extension to this question.
Here I have the same problem with a slightly different situation.

The following is two tables in a database

tblTemp
TempPK AutoNumber
PsNo String

tblOrders
OrderPK AutoNumber
PsNo String


Both tables have several more fields, but the only common field between them is PsNo. No relationship between them.

What @Minty and @isladogs suggested in previous thread, searches for an exact match between PsNo in two tables.
Here I'm looking for a way to do the same thing but with a fuzzy match.
I need to check for only 9 digits of PsNo in both tables (from left) and not the whole string..
Let me give you an example:

tblTemp
TempPKPsNo
1245389447-00
2245717248-00
3245730245-00

tblOrders
OrdersPKPsNo
1245389447-00*
2245389447-00A
3245730245-00
4245730245-01
5245730245-00B

The query must return only the second record of tblTemp, because left 9 digit of 245717248-00 doesn't exits in tblOrders.
But left 9 digit of first record has 2 occurrence and the third record has 3 occurrence in tblOrders.

I know this situation is very odd, but any kind of help is appreciated.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 06:28
Joined
Oct 29, 2018
Messages
21,454
Well, one way to do it is to create two separate queries based on each table where you can use the Left() function to add a calculated column showing the first 9 digits. You can then use the same technique you learned earlier; but instead of comparing two tables, you will be comparing two queries.
 

Sun_Force

Active member
Local time
Today, 22:28
Joined
Aug 29, 2020
Messages
396
Well, one way to do it is to create two separate queries based on each table where you can use the Left() function to add a calculated column showing the first 9 digits. You can then use the same technique you learned earlier; but instead of comparing two tables, you will be comparing two queries.
thanks for replying.
I already had done that before posting. But the result never shows up. I waited for more than 15 minutes but seems that left function takes a long time to work on 138847 records. I had to give up and kill Access process from the task manager.


2021-03-17_12-00-22.jpg
I
 

theDBguy

I’m here to help
Staff member
Local time
Today, 06:28
Joined
Oct 29, 2018
Messages
21,454
thanks for replying.
I already had done that before posting. But the result never shows up. I waited for more than 15 minutes but seems that left function takes a long time to work on 138847 records. I had to give up and kill Access process from the task manager.


View attachment 90035 I
Hi. I am using my phone, so please pardon any typos but try:
Code:
SELECT TempPK
FROM qryTemp
INNER JOIN qryOrders
ON qryTemp.PS=qryOrders.PS
WHERE qryOrders.PS Is Null
(untested)
Sent from phone...
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 21:28
Joined
May 7, 2009
Messages
19,233

theDBguy

I’m here to help
Staff member
Local time
Today, 06:28
Joined
Oct 29, 2018
Messages
21,454

Sun_Force

Active member
Local time
Today, 22:28
Joined
Aug 29, 2020
Messages
396
*Note:
you must paste in SQL view. it will complain in Design view.
Even in sql view:

2021-03-17_13-36-10.jpg


I changed it to tblOrders.PsNo="" but now the result is blank. I know I have 10 or 11 unmatched result. And the query fails to show them.
At present I'm doing this process with a function. I hoped a query being faster. But the above query took several minutes to show the result.

I attached a database for playing with.

thanks again for your help.
 

Attachments

  • Database8.zip
    2 MB · Views: 231

Users who are viewing this thread

Top Bottom