Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Simple Question about the IN condition

Posted on 2013-01-18
3
Medium Priority
?
313 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
3 Comments
 
LVL 78

Accepted Solution

by:
slightwv (䄆 Netminder) earned 1200 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 800 total points
ID: 38794161
order of operations

AND before OR
0
 

Author Closing Comment

by:Mark_Co
ID: 38794182
Thanks
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video shows how to recover a database from a user managed backup

886 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