?
Solved

Simple Question about the IN condition

Posted on 2013-01-18
3
Medium Priority
?
312 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 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

719 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