Home > Ask the Oracle Experts > Questions & Answers > Exactly one row? At least one row? (Part 2)
Ask The Oracle Expert: Questions & Answers
EMAIL THIS

Exactly one row? At least one row? (Part 2)

Rudy Limeback EXPERT RESPONSE FROM: Rudy Limeback

Pose a Question
Other Oracle Categories
Meet all Oracle Experts
Become an Expert for this site
>
QUESTION POSED ON: 17 October 2002
Here is the rest of Rudy's response. (See part one.)

>
EXPERT RESPONSE

To summarize, if you want at least some number of rows, use an inequality in the HAVING clause of the IN?(subquery). If you want at least one row, the HAVING clause is redundant, and you should use an EXISTS?(subquery):

select id
     , loc_numb
     , loc_prec
  from item_loc  xx
 where id in 
       ( select id
           from item_loc
          where loc_prec = 'S'
         group by id
         having count(*) = 1 )
   and exists
       ( select 1
           from item_loc
          where id = xx.id
            and loc_prec = 'P' )

Note that the EXISTS subquery is correlated. The EXISTS syntax gives the database optimizer a chance to improve performance, since the EXISTS subquery will be true as soon as the first row is found. As soon as the row is found, grouping is not necessary.

In summary, use EXISTS if you are looking for one or more rows. If you want exactly some number, including one, or at least some number where the number is two or more, then grouping is necessary, and you can't use EXISTS.


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


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 ExpertsMultimediaWhite 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