Hi,
This script is returning true for more than one OR statement, resulting in too many records being returned. I want it to stop if the first one is a match. I'm thinking that should be an IIF statement (instead of using OR... AND as I've done here) but not sure of how to fit that into a WHERE clause. - SELECT Employees.[LAST_NAME], Employees.[FIRST_NAME], Employees.[Pay_Method], Employees.[EMAIL_ADR], Employees.[Dept], Employees.[Leader], Members.[Last], Members.[First]
-
FROM Employees, Members
-
WHERE (InStr(basAlphNum(Employees.[LAST_NAME]),Mid(basAlphNum(Members.Last),1,5))
-
AND InStr(basAlphNum(Employees.[FIRST_NAME]),Mid(basAlphNum(Members.First),1,5)))
-
-
OR (InStr(basAlphNum(Members.[Last]),Mid(basAlphNum(Employees.[LAST_NAME]),1,5))
-
AND InStr(basAlphNum(Members.[First]),Mid(basAlphNum(Employees.[FIRST_NAME]),1,5)))
-
-
OR (InStr(basAlphNum(Employees.[LAST_NAME]),Mid(basAlphNum(Members.Last),1,5))
-
AND InStr(basAlphNum(Members.[First]),Mid(basAlphNum(Employees.[FIRST_NAME]),1,5)))
-
-
OR (InStr(basAlphNum(Members.[Last]),Mid(basAlphNum(Employees.[LAST_NAME]),1,5))
-
AND InStr(basAlphNum(Employees.[FIRST_NAME]),Mid(basAlphNum(Members.First),1,5)))
-
-
OR InStr(basAlphNum(Members.[Last]),Mid(basAlphNum(Employees.[LAST_NAME]),1,5))
-
-
OR InStr(basAlphNum(Employees.[LAST_NAME]),Mid(basAlphNum(Members.Last),1,5))
-
-
GROUP BY Employees.[LAST_NAME], Employees.[FIRST_NAME], Employees.[Pay_Method], Employees.[EMAIL_ADR], Employees.[Dept], Employees.[Leader], Members.[Last], Members.[First]
-
ORDER BY (Employees.[LAST_NAME]);
11 1285
@webbeacon: please give more information bout your data structure, Table's fields, and what are you planning to do ?
We can understand the code, but can't guess what you want to do, so you should provide more detail before we can start to help you, thanks.
Thanks hvsummer - basically I'm trying to do an approximate match of first and last names in two lists. I think the table structure is explained in the SELECT statement so I'm not sure what you're looking for in that regard... sorry I'm new here!
The basAlphNum function is a public function I found that strips out all spaces and punctuation. I'm using MID to restrict the matching portion to 5 characters. These two things exist to capture differences between the two lists (ie. "Marie Louise" vs. "Marie-Louise" vs. "Marie")
With the addition of lines 15 and 17, I was hoping to widen my net by including matches for just first or last names, after having gone through the four combinations first... but then I'm getting a lot of duplicate matches.
My "pie in the sky" is to get this to a point where I don't need to do any manual modifications to either list for it to work, or at least keep them to a minimum.
Hope that helps
Thank you!
Here's an example of the problem. I've hidden part of the name fields for privacy but you can see the highlighted record is a correct match; all the records below that are incorrect matches.
My hope is that I can modify this in such a way that when it makes a match, it stops looking through the rest of the OR statements, thereby avoiding duplicates. Hope that makes sense.
The fields in a SELECT statement tell us almost nothing about the table structure. They may as well be called Field1, Field2, etc. It doesn't tell us the data type, default values, range of data, primary keys, relationships between tables, and so on. All of this information is important when trying to write a query.
Also, some of us are behind firewalls that block third party storage sites like imgur. It would be better if you typed in the sample data and results in the thread itself.
Thanks for the feedback Rabbit. The fields are all Short Text. They're populated with a list of employees. So an example of a record would be (Sorry I'm not sure how to do this in a better way) - Table: Employees
-
LAST_NAME FIRST_NAME Pay_Method EMAIL_ADR Dept Leader
-
Anderson Marie-Louse Salary mlanderson@company.com OPS Joe Leader
-
-
Table: Members
-
Last First
-
Anderson Marie Louise
There is no primary key and I'm not sure what you mean by the relationship between the tables.
The example I posted at Imgur shows a record that's being returned several times based on the last two OR statements, where it only tries to match the last name and ignores the first name. I understand why that's happening, just don't know an alternative and am hoping someone can point me in the right direction.
Example:
Last name "Anderson" is matching once correctly, but then also matching on any other last name containing the string "ander". I want it to try to match last name only if it fails to find last name AND first name.
I hope that answers your questions.
Have one query that doesn't have the last 2 filters.
Then create a new query that has the last 2 filters but also outer joins to the first query to filter those that found matches out of the result set.
Union those 2 queries together to get a single result set.
But let me float a different approach. What you really want is to try to find the best match possible between the two tables. What you want is fuzzy string matching. There are different algorithms you can look at rather than relying on strict substring matching. For example, there are phonetic algorithms that tell you how a string "sounds" and you can see if the "sound" of the two strings are a match. For that, you can look into the Soundex or Metaphone algorithms. There are also edit distance and substring content matching algorithms that produce a score based on how similar the content of each string is compared to another. For that, you can look into the Levenshtein or NGram algorithms.
Thank you! You're absolutely right, I'm trying to do fuzzy matching. I tried Soundex, but it matched a lot of records incorrectly. I'll look at the other two... really appreciate the tip!
I suggested soundex because of how easy it is to implement. But you're right, it's not very accurate. Also, I suggested 3 additional approaches other than soundex in my post, not 2. The other 3 are much more difficult to implement.
Hi webbeacon, I don't know where you are in this process now, but if you're interested, I created a new article on this forum yesterday that has an implementation of the double metaphone phonetic algorithm.
Thanks Rabbit! I'm thinking for my purposes, the ngram technique is probably best. I haven't had a chance to play with it yet, need to figure out how to apply it in Access VB. I really appreciate your help though and thinking of me after your post!
If you run into any issues, feel free to create a new thread with what you've attempted so far in terms of implementation and we can help you through it.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: RT |
last post by:
I have a registration system that I¹m working on that requires some
information to be entered only once (ie. Company name, cost & dates)
Does anyone know how I can set up in php so only one record...
|
by: mimisam |
last post by:
I have a table with a few hundreds records of products information. I
need to retrieve the top 10 records based on the sum of the products
quantity. My query is as below:
Select *, sum(qty) as...
|
by: ChadDiesel |
last post by:
Everyone on this group has been a great deal of help. I have another
question that I could use some help with. Once again, here is a picture of
my form:
...
|
by: deko |
last post by:
Is there any way to limit the number of records loaded into a ListBox?
I looked at qdf.MaxRecords (to apply to the query that is the RowSource of
the ListBox) but that only applies to ODBC data...
|
by: aaron.reese |
last post by:
Guys,
this is my problem:-
I have records which are linked by two fields on a left inner join
(there may be 0,1 or more records in the right hand table)
The relationship is not unique (it's...
|
by: Bob |
last post by:
I am developing an ASP.NET application that needs to archive documents and
support the retrieval of them. When the document is stored, the user needs
to be able to indicate whether it is a public...
|
by: David |
last post by:
Hi,
I have an asp page which I want to display 10 records with a
'Previous' and 'Next' link underneath for navigating through the rest
of the recordset.
I have the page displaying the first...
|
by: jackiefm |
last post by:
I have a crosstab query that I need the returned records to be limited to the top 10 for each group. How can I accomplish this? My sql
TRANSFORM Count(Violation.Driver) AS CountOfDriver
SELECT...
|
by: Jollywg |
last post by:
I'm using 2 forms one is a customer entry form and the second is an invoice entry form for that particular customer. I'm sending the invoice form the customer id number to keep the link up. The form...
|
by: donilourdu |
last post by:
hi,
I am trying to retrive data from MYSQL database.I am using limit to fetch the data.It will fetch two rows instead of fetching ten rows.But when i try to debug it fetches eight rows instead...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |