473,587 Members | 2,580 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.Compa ny

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 1103
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.Author name, WorkBook.FirstN ame, WorkBook.LastNa me, WorkBook.Title, WorkBook.Email, WorkBook.Compan y, WorkBook.[Lead Status]

FROM WorkBook LEFT JOIN Customers ON WorkBook.[Company] = Customers.[Company]

WHERE (((Customers.Co mpany) Like "*" & [WorkBook.Compan y] & "*"));



This produced the same results as the query I posted above.

I have in my WorkBook.Compan y field "FirstEnerg y Inc" and in my Customers.Compa ny field I have "FirstEnerg y" 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.Author name, WorkBook.FirstN ame, WorkBook.LastNa me, WorkBook.Title, WorkBook.Email, WorkBook.Compan y, WorkBook.[Lead Status]

FROM WorkBook, Customers

WHERE Customers.Compa ny 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

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

Similar topics

1
3149
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 that has the 'Ceiling Tile' in it, but when I run the query I get a pop up window that says, "Invalid Argument" What can be done?
1
1665
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 appears multiple times on one employee's report. However, if the same record(s) appear on any other employee's report, it means they collaborated on...
3
4807
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 the Row field, which is returned automatically. and an example of a row that it has returned duplicate. I have verified that the row only shows...
3
2256
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, but I probably have not properly implemented the solutions I find. I am trying to make a page to allow personnel the ability to search our...
2
1336
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 employee has passed that module. There are 21 modules. I am trying to generate a report which shows each technician if and only if they have...
2
784
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 duplicate; UserID and WeekEndingDate. If more than 1 record is found for the same combination I want to have a pop-up message saying that the combo...
7
2465
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 characters and may look as follows: "0000000" "10112B1A" "0000" "***111B001" "0000000000" "111000" "0" "00000000000"
3
2151
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 2009-05-08 10:53:24.380 2009050867900036 2007111699900838 2009-05-08 11:00:31.870 2009050867900041 2007111699900838 I need assistance in writing a...
3
2661
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, field3,field4, field5 , field6,
16
5119
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 = ActiveSheet.Cells(I, 2).Value 'get URLs
0
7918
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7843
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8220
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6621
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5713
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5392
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3840
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2353
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1185
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.