IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Difference between "IN" and "=" using su


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
dirceu.alves

New User


Joined: 03 Aug 2005
Posts: 18

PostPosted: Fri Nov 06, 2009 10:19 pm
Reply with quote

Hi All,

Would anyone tell me what is the difference between the use of "IN" clause and "=" when using subqueries? This is what I'm talking about...

SELECT *
FROM TABLE_1 A, TABLE_2 B
WHERE A.COD = B.COD AND
A.SEQ_NO IN
(SELECT MAX(C.SEQ_NO)
FROM TABLE_1 C
WHERE C.COD = A.COD)


SELECT *
FROM TABLE_1 A, TABLE_2 B
WHERE A.COD = B.COD AND
A.SEQ_NO =
(SELECT MAX(C.SEQ_NO)
FROM TABLE_1 C
WHERE C.COD = A.COD)


Thank you
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6965
Location: porcelain throne

PostPosted: Fri Nov 06, 2009 10:50 pm
Reply with quote

Code:
(SELECT MAX(C.SEQ_NO)
FROM TABLE_1 C
WHERE C.COD = A.COD)


if the subquery returns only one row then = will work,
if more than one row is returned and you have used =
you will receive a -811 sqlcode.

if the subquery returns one row or more than one row and you have used 'IN'
the subquery has returned an IN-LIST which will then allow your 'outer query' to return either a +100 or +000 sqlcode.
Back to top
View user's profile Send private message
View previous topic : : View next topic  
Post new topic   Reply to topic All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Structured Data and Nested Loops via ... COBOL Programming 0
No new posts Difference between joblib and steplib JCL & VSAM 2
No new posts Pull data using date difference betwe... DB2 6
No new posts Difference between PLT txn and schedu... CICS 3
No new posts PuTTY - "User is not a surrogate... IBM Tools 5
Search our Forums:


Back to Top