Solved

Simple Question about the IN condition

Posted on 2013-01-18
3
309 Views
Last Modified: 2013-01-18
So i did a SQL two different ways. One is with an OR and the other is with the IN condition.

I thought the IN was an alternate way oF using OR (for the purpose of cutting down on using ORs, that iS).

Why then when I do this, do I get different results?

SELECT 
  COUNT(*)
FROM table a
WHERE 
type = '102' OR type = '103'
      AND SEQ = '1' --current row of data, if desired
      AND STATUS = 'A' --active  ('I' = inactive), if desired

Open in new window

THE ABOVE RETURNS A FEW HUNDRED MORE ROWS THAN THE BELOW

and this:

SELECT 
COUNT(*)
FROM TABLE A
WHERE TYPE IN ('102','103')
      AND SEQ = '1' --current row of data, if desired
      AND STATUS = 'A' --active  ('I' = inactive), if desired
      

Open in new window

0
Comment
Question by:Mark_Co
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 77

Accepted Solution

by:
slightwv (䄆 Netminder) earned 300 total points
ID: 38794156
It's a logic issue.

a or b and c
is different than:
(a or b) and c

Try this to see if the results are the same:

WHERE
(type = '102' OR type = '103')
      AND SEQ = '1' --current
0
 
LVL 74

Assisted Solution

by:sdstuber
sdstuber earned 200 total points
ID: 38794161
order of operations

AND before OR
0
 

Author Closing Comment

by:Mark_Co
ID: 38794182
Thanks
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question