473,513 Members | 2,525 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Query two tables and duplicates with wildcards

14 New Member
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

Expand|Select|Wrap|Line Numbers
  1. SELECT WorkBook.ID, WorkBook.Authorname, WorkBook.FirstName, WorkBook.LastName, WorkBook.Title, WorkBook.Email, WorkBook.Company, WorkBook.[Lead Status]
  2.  
  3. FROM WorkBook LEFT JOIN Customers ON WorkBook.[Company] = Customers.[Company]
  4.  
  5. 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.

===
Aug 26 '16 #1
15 1091
PhilOfWalton
1,430 Recognized Expert Top Contributor
Try
Expand|Select|Wrap|Line Numbers
  1. WHERE (((Customers.Company) Like "*" & [WorkBook.Company] & "*"));
Phil
Aug 26 '16 #2
RiskWatch
14 New Member
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.
Aug 26 '16 #3
ADezii
8,834 Recognized Expert Expert
Give this a shot, don't think the Tables can be joined:
Expand|Select|Wrap|Line Numbers
  1. SELECT WorkBook.ID, WorkBook.Authorname, WorkBook.FirstName, WorkBook.LastName, WorkBook.Title, WorkBook.Email, WorkBook.Company, WorkBook.[Lead Status]
  2. FROM WorkBook, Customers
  3. WHERE WorkBook.Company Like "*" & [Customers].[Company] & "*";
  4.  
Aug 26 '16 #4
RiskWatch
14 New Member
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.
Aug 26 '16 #5
RiskWatch
14 New Member
http://imgur.com/a/T09F5
Aug 26 '16 #6
RiskWatch
14 New Member

Aug 26 '16 #7
RiskWatch
14 New Member
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?
Aug 26 '16 #8
RiskWatch
14 New Member
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.
Aug 26 '16 #9
ADezii
8,834 Recognized Expert Expert
Try using the DISTINCT Predicate:
Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCT WorkBook.ID, WorkBook.Authorname, WorkBook.FirstName, WorkBook.LastName, WorkBook.Title, WorkBook.Email, WorkBook.Company, WorkBook.[Lead Status]
  2. FROM WorkBook, Customers
  3. WHERE WorkBook.Company Like "*" & [Customers].[Company] & "*";
  4.  
Aug 26 '16 #10
RiskWatch
14 New Member
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.)
Aug 26 '16 #11
RiskWatch
14 New Member
http://imgur.com/a/nTLsX
Aug 26 '16 #12
RiskWatch
14 New Member

Aug 26 '16 #13
ADezii
8,834 Recognized Expert Expert
I honestly need more info than what the Image is showing.
Aug 26 '16 #14
RiskWatch
14 New Member
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.
Aug 26 '16 #15
RiskWatch
14 New Member
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.
Aug 26 '16 #16

Sign in to post your reply or Sign up for a free account.

Similar topics

1
3137
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...
1
1661
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...
3
4798
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...
3
2247
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,...
2
1334
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...
2
780
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...
7
2461
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...
3
2145
benchpolo
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 ...
3
2653
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, ...
16
5093
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 =...
0
7260
marktang
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,...
0
7384
Oralloy
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,...
0
7539
jinu1996
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...
1
7101
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...
0
7525
tracyyun
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...
0
5686
agi2029
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,...
1
5089
isladogs
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...
0
4746
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...
0
3222
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.