Solved

Simple Question about the IN condition

Posted on 2013-01-18
3
303 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 76

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 73

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Subquery in Oracle: Sub queries are one of advance queries in oracle. Types of advance queries: •      Sub Queries •      Hierarchical Queries •      Set Operators Sub queries are know as the query called from another query or another subquery. It can …
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
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 copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

743 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now