Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Duplicate query based on partial match

Status
Not open for further replies.

Philly44

Programmer
Jul 17, 2001
277
CA
I have duplicate query setup that works fine providing I only want to match against the entire lastname. I need it to be able to match against the first 3 characters of the lastname. I have tried using the left function to no avail. Is there any other way I can query for duplicates against the first 3 chars of a string?

Thanx in advance
 
how about creating a select query and adding an extra columkn in the query with the first three letters of the surname in there

so fndName:left([Surname],3)

the create a query based on that query and do your duplicates doobrie ?
 
Thancks but I tried that an Access nevewr comes back from that type of query
 
This query may help you some. It definitely has disadvantages in that it will only show you the first 3 characters of the last name and no other fields in the table, but it will run quickly.

Chance's answer is the way to get what you want, but if you have many records in your table it really will suck the memory right out of your computer.


SELECT DISTINCTROW Left([LastName],3) AS First3, Count([LastName) AS CountOfLastName FROM [yourtable]
GROUP BY Left([LastName],3)
HAVING (((Count(LastName)>1));



Here's a variation of Chance's query. It runs quickly on my system, but it could drag on yours.

SELECT DISTINCTROW Left([LastName],3) AS First3, recID, FirstName
FROM [yourtable]
WHERE (((Left([LastName],3)) In (SELECT Left([LastName],3) FROM [yourtable] As Tmp GROUP BY Left([LastName],3) HAVING Count(*)>1 )))
ORDER BY Left([LastName],3);
Maq B-)
<insert witty signature here>
 
Thanks a bunch guys the code works. Slow as heck but hey thats the nature of the beast. The user is fine with it anyways.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top