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
Solved

Simple Question about the IN condition

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

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
migration MS SQL database to Oracle 30 68
run sql script from putty 4 67
pivot rows to columns 1 35
Loading flat file data in tables 2 41
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…
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 recover a database from a user managed backup

829 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