Home > Ask the Oracle Experts > SQL Questions & Answers > Searching with multiple keywords
Ask The Oracle Expert: Questions & Answers
EMAIL THIS

Searching with multiple keywords

Rudy Limeback EXPERT RESPONSE FROM: Rudy Limeback

Pose a Question
Other Oracle Categories
Meet all Oracle Experts
Become an Expert for this site


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


>
QUESTION POSED ON: 29 January 2003
I'm looking for a way to search a memo field in MS Access by multiple keywords. I currently have a memo field that contains a summary of the contents in a file box. I can search it fine by one word, but if I could search with multiple keywords, the search would return fewer, but more accurate, results. For example, if someone were to search for "2001 Payroll" (without the quotes), a search would return all records that contained the words "2001" and "Payroll". I would like to be able to make the search work for multiple words (much like a Web search engine).

>
EXPERT RESPONSE

You can achieve this by writing your SELECT statement with multiple conditions in the WHERE clause. If you are creating the search query in Access yourself, whether in Design or SQL View, you want to end up with something like this (in SQL View) --

select columns
  from yourtable
 where memofield like '*2001*'
    or memofield like '*Payroll*'

Just code as many conditions as you have keywords. Note the use of the asterisk as wildcard character; other databases use a percent sign.

Your next question is probably going to be "Well, how do I generalize that, so that I, or, more specifically, one of my users, can enter any number of keywords?"

How you deal with this will depend entirely on the language that you're using, and the way that you design the search interface. For example, you could offer multiple input fields, one per keyword, or else just one input field, like almost every popular search engine. In either case, you will have to write some code in a scripting language. If this is an Access application, you would write an Access module. If it's a Web page, you'll probably write some ASP or ColdFusion code.

What the script needs to do is figure out how many keywords were entered (by detecting which fields are empty, if you use more than one keyword field, or by detecting the blanks between keywords, if you use one field). The script will dynamically build the WHERE clause, concatenating an additional condition for each keyword after the first one with an OR. You could also have an option for "exact phrase" in which case you would insert the entire contents of the field into just one WHERE clause condition.

For More Information


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


RELATED CONTENT
SQL
IN list or series of OR conditions?
Connecting tables in a database
SQL query for co-authored books
Querying complex derived tables
SQL string functions
Changing a NULL column to NOT NULL
SQL for hourly totals for the last 48 hours
LEFT OUTER JOIN to a MIN/MAX row
Normalizing a crosstab table
Querying metadata and data at the same time

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary



Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice

HomeNewsTopicsTipsAsk the ExpertsWebcastsWhite PapersProductsBlogs
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




All Rights Reserved, Copyright 2003 - 2008, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts