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: 17

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: 6966
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts PuTTY - "User is not a surrogate... IBM Tools 5
No new posts Timestamp difference and its average ... DB2 11
No new posts Newbie Stuck on "Duplicate Datas... TSO/ISPF 5
No new posts Difference when accessing dataset in ... JCL & VSAM 7
No new posts RABBIT HOLE NEEDED - "Live"... All Other Mainframe Topics 0
Search our Forums:

Back to Top