Home > Ask the Oracle Experts > SQL Questions & Answers > Can one group LIKEs together?
Ask The Oracle Expert: Questions & Answers
EMAIL THIS

Can one group LIKEs together?

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: 22 December 2003
Can one group LIKEs together, such as:
select * from A 
 where B like ('ccc', 'ddd', 'eee')

>
EXPERT RESPONSE

No. You have to "distribute" the LIKE operator over the individual items in your list. This is not just a syntax requirement, it is also good coding practice, because it allows you to concentrate on exactly what you mean.

First, you will need to decide whether you want the conditions connected with ORs or ANDs. Second, if you want all three strings present, do the strings have to exist in the given sequence? Finally, you should really use wildcard characters; otherwise, each LIKE in effect becomes a strict equality, and then only the OR version even makes sense.

Find rows where B contains any one (or two, or three) of the three strings:

select * 
  from A 
 where B like '%ccc%'
    or B like '%ddd%'
    or B like '%eee%'

Find rows where B contains all three strings, in any order:

select * 
  from A 
 where B like '%ccc%'
   and B like '%ddd%'
   and B like '%eee%'

Find rows where B contains all three strings, in the given order:

select * 
  from A 
 where B like '%ccc%ddd%eee%'

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