473,320 Members | 1,883 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How do i use LIKE for a search query?

OuTCasT
374 256MB
I cant remember how to do the search with LIKE...

Ive got a textbox where the user will search for a company name
now i want them to be able to type in anything and it must bring back the companies with that text in.....

???
Jul 30 '08 #1
7 1471
Delerna
1,134 Expert 1GB
where field like 'str%' --returns records where field begins with str
where field like '%str%' --returns records where field contains str
where field like '%str' --returns records where field ends with str
Jul 30 '08 #2
OuTCasT
374 256MB
where field like 'str%' --returns records where field begins with str
where field like '%str%' --returns records where field contains str
where field like '%str' --returns records where field ends with str
I want to be able to type in anything.

For instance if there was a company called WebSol-IT in the db
and i typed in Web or Sol or IT in the textbox then it would bring that back WebSol-IT back
Jul 30 '08 #3
code green
1,726 Expert 1GB
and i typed in Web or Sol or IT in the textbox then it would bring that back WebSol-IT back
Then Delernas LIKE %str% will work.
Or are you trying to do Google type search - typing "Web OR Sol OR IT" in the box?
Jul 30 '08 #4
OuTCasT
374 256MB
Then Delernas LIKE %str% will work.
Or are you trying to do Google type search - typing "Web OR Sol OR IT" in the box?
its like a company will book in a item to get repaired, they come back 2 days later and tell the guy they want to pick up there item, he asks them there companyname and he types it in and it will search for that company, so even if he spelt it wrong, or put a space between the words even though there isnt it would still bring back something in that liking.
Jul 30 '08 #5
code green
1,726 Expert 1GB
so even if he spelt it wrong, or put a space between the words even though there isnt it would still bring back something in that liking.
This is tricky.
I suppose it could be done in SQL but I would prefer using code.
If it was spelt wrong you would need a lookup table for common mispellings or
break up the word into chunks and look for partial matches.
Spaces again could be broken into chunks to look for each seperated word or the whole word with spaces removed.
I wrote a similar bespoke program a couple of years ago.
I shudder to think how un-sophisticated that probably looks now
Jul 30 '08 #6
ck9663
2,878 Expert 2GB
That'll be a search engine/fuzzy matching algorithm. If you can write that efficiently, you can get rich coz that's how most search engine works. You can replace google ;)

-- CK
Jul 30 '08 #7
Delerna
1,134 Expert 1GB
I think you could probably handle spaces by replacing them with %.
That way the entry "Col Turner Industries" would look like

where field ='%Col%Turner%Industries%'
I'll have to try that one day.

Or maybe you could use the replace function on both sides of the where equation to replace spaces with an empty string. Can't remember the exact syntax
something like
where replace(field,' ','') = '%' + replace(@param.' ','') + '%'




Handling Mis-spellings
Yea....good luck with that :)
As CK said, You could replace Google
Actually, if I knew the efficient answer I would keep it to myself
Jul 30 '08 #8

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

Similar topics

0
by: Phil Powell | last post by:
The table already has a fulltext index and from there I can use the MySQL fulltext search query to get results as well as the relevancy score. The problem I have is that MySQL has a default...
2
by: TH | last post by:
I am (still :) working on a recipe database. Now I am trying to figure out how to set it up for an ingredient search. What I want it to be able to do is to search by one ingredient, sometimes by...
7
by: John | last post by:
hi, i have created a search form, and i want to search for a specific item in a field. e.g. i have a field called colour, which has record1 = 'red, blue, green' and another record2 = 'red' ...
0
by: | last post by:
I have a question about spawning and displaying subordinate list controls within a list control. I'm also interested in feedback about the design of my search application. Lots of code is at the...
1
by: cglewis03 | last post by:
Hello, I am trying to build a search form with several different options to choose from. Currently it is set up to open within the same window if a single option is selected and open within a...
6
by: jej1216 | last post by:
I am trying to put together a PHP search page in which the user can select none, one, two, or three fields to search, and then the results php will build the SQL with dynamic where caluses to reflect...
13
by: jfarthing | last post by:
Hi everyone! I am using the script below to search a db. If the is more than one match in the db, all goes well. But if there is only one match in the db, nothing gets displayed. Any...
13
by: Robertf987 | last post by:
Hi, Yet another thing I need help with I'm affraid. I'll first explain what I want, then I'll try to explain what I have. I'm using Microsoft Access 2000. What I want is to be able to do a...
5
by: th1982 | last post by:
HI All I have a search page' s result which view 3results/per page,but my "next" link to view next page is not working. Here is my code : <?php // Get the search variable from URL ...
8
by: Sham | last post by:
I am trying to perform the following query on a table that has been indexed using Full Text Search. The table contains multiple columns than have been indexed. (Below, all xml columns are...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.