Hello to all.
I am comparing two tables [Customers] and [Workbook]
I am trying to identify, in the table [WorkBook] places where the "Company" field is similar or the same to the Customers.Company
I am now able to successfully identify exact matches, but what I need is to place wildcards on either side of my search function.
I have the following SQL statement - SELECT WorkBook.ID, WorkBook.Authorname, WorkBook.FirstName, WorkBook.LastName, WorkBook.Title, WorkBook.Email, WorkBook.Company, WorkBook.[Lead Status]
-
-
FROM WorkBook LEFT JOIN Customers ON WorkBook.[Company] = Customers.[Company]
-
-
WHERE (((Customers.Company) Like [WorkBook.Company] & "*"));
The statement above will generate a list of matches, but only exact matches. I need to be able to identify the same thing but with variations on either side.
I believe the issue is in my last line of code but I have not been able to figure it out.
This SQL statement successfully identifies the exact matches between WorkBook and Customers but I want to use a wildcard operator like % or * on either side of the company name and have those show up as well.
That is to say, imagine I have in my list of customers "Microsoft" ; I want to have wildcards so that if in the workbook table I had "Microsoft Inc" or "Super Microsoft" or "Super Microsoft Inc" they would also be identified.
Thank you for any help and sorry if this is a simple request.
===
15 1091
Try -
WHERE (((Customers.Company) Like "*" & [WorkBook.Company] & "*"));
Phil
Hi Phil,
I tried it as follows:
SELECT WorkBook.ID, WorkBook.Authorname, WorkBook.FirstName, WorkBook.LastName, WorkBook.Title, WorkBook.Email, WorkBook.Company, WorkBook.[Lead Status]
FROM WorkBook LEFT JOIN Customers ON WorkBook.[Company] = Customers.[Company]
WHERE (((Customers.Company) Like "*" & [WorkBook.Company] & "*"));
This produced the same results as the query I posted above.
I have in my WorkBook.Company field "FirstEnergy Inc" and in my Customers.Company field I have "FirstEnergy" and this query did not pull the record from WorkBook.
It should be noted that with your adjustment it also pulls the exact matches, but not the variations (wildcards) ; This is exactly the error I encountered with my original query.
ADezii 8,834
Recognized Expert Expert
Give this a shot, don't think the Tables can be joined: - SELECT WorkBook.ID, WorkBook.Authorname, WorkBook.FirstName, WorkBook.LastName, WorkBook.Title, WorkBook.Email, WorkBook.Company, WorkBook.[Lead Status]
-
FROM WorkBook, Customers
-
WHERE WorkBook.Company Like "*" & [Customers].[Company] & "*";
-
ADezii,
Excellent! Your solution does in fact pull the items like I want it to. It even seems to sort them at the top of the list.
The only issue I have is that it also includes ALL of the records from WorkBook below. (So now I have duplicate records and records I didn't want identified at all.)
I will post a screen shot for clarification, but can only show the IDs as some of the other data is sensitive.
If you follow the link to the image, you'll see that the records at the top 12,13,14 and 11 are the correct records that I wanted to identify with this query.
Unfortunately having all of the records from WorkBook duplicated below it is ruining what I was trying to achieve.
Is there a way to filter out 1-14 and only keep the 12,13,14,11 using a single query? Will I have to do another query to remove duplicates?
I tried reversing the last line as such:
SELECT WorkBook.ID, WorkBook.Authorname, WorkBook.FirstName, WorkBook.LastName, WorkBook.Title, WorkBook.Email, WorkBook.Company, WorkBook.[Lead Status]
FROM WorkBook, Customers
WHERE Customers.Company Like "*" & [WorkBook].[Company] & "*";
This brings back being unable to identify wildcards but pulling exact matches.
ADezii 8,834
Recognized Expert Expert
Try using the DISTINCT Predicate: -
SELECT DISTINCT WorkBook.ID, WorkBook.Authorname, WorkBook.FirstName, WorkBook.LastName, WorkBook.Title, WorkBook.Email, WorkBook.Company, WorkBook.[Lead Status]
-
FROM WorkBook, Customers
-
WHERE WorkBook.Company Like "*" & [Customers].[Company] & "*";
-
ADezii,
We are painfully close.
Your last post just produces a copy of the WorkBook and has removed the 4 records it was identifying before. So, roughly the opposite effect.
To summarize:
Your initial code successfully identified the matches between [Customers] and [WorkBook], including wildcards and filtered them to the top of the table. However, it included a copy of the entire [WorkBook] table below the results.
Your second code removed what we had identified previously and left only the copy of the [WorkBook] table.
Screenshot of the new results included below.
(Thank you for all of your help, I'm amazed we've gotten this far and will be blown away if we can get it working.)
ADezii 8,834
Recognized Expert Expert
I honestly need more info than what the Image is showing.
ADezii,
Give me a few moments to build out an example that I can share, I'm working with sensitive information. I'll attach some additional links in just a few minutes.
There must be some "user" error or something I have overlooked.
When I started to use your first solution with test data, it works perfectly.
I will have to take a closer look why it will not work with my real data.
Thank you for all your help. I will mark your first response as the correct solution and create a new post if and when I identify the issue with my data.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Joseph VanWagoner |
last post by:
I have a field called 'Details' that is of type 'Memo' I have a query
that says:
"SELECT * FROM TableName WHERE Details LIKE '*Ceiling Tile*';"
I know that there are memos in the Details field...
|
by: MHenry |
last post by:
Hi,
I have a table with duplicate records.
Some of the duplicates need to be eliminated from the table and some
need not.
A duplicate record does not need to be eliminated if the one record...
|
by: Sim Zacks |
last post by:
I am using 8.0 beta 1 on an RH 8 Linux server.
I have a union query that I am converting from access (where it
worked) and it is returning duplicates. The only difference between
the two rows is...
|
by: george.lengel |
last post by:
Hello experts,
I have been struggling for days to solve this problem and every
suggestion I find via Google does not work for me. There is probably a
solution out there that will do what I want,...
|
by: limpsharp |
last post by:
Hi,
I'm at the end of a work project and the final report has got me stumped.
I have a table of employees, a table of modules and a link table of modules and employees and whether or not the...
| |
by: juster21 |
last post by:
I have a data-entry application which saves records to an Access db. I need to build in a query to search for duplicate entries before a save is performed. There are 2 fields that would generate a...
|
by: servantofone |
last post by:
I'm using Access 2003. I'm building a query and wish to display all records with values in a certain field (HIST) made up of all zeros. The field has a range of text values including alpha-numeric...
|
by: benchpolo |
last post by:
I'm not sure if this is the right section to post, but somehow I cannot post a thread in SQL server section.
CreateDate AccountNo OriginalAcctNo ...
|
by: pstsqllearner |
last post by:
I'm using this to create a view for duplicates , but no of records coming out of this view are more than I'm passing in: can anybody help ?
CREATE VIEW test AS
(
SELECT field1,
field2,
...
|
by: aflores41 |
last post by:
Sub macro1()
'Dim frm As UserForm
Dim I As Integer
'To could be as many as you want. I only put 25 as a limit.
For I = 1 To 25
Dim a As String
a = Sheet1.Cells(I, 1).Value
Dim b As String
b =...
|
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: 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: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
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...
| |
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |