Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Difference between "IN" and "=" using su

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: Difference between "IN" and "=" using su
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: 6968
Location: porcelain throne

PostPosted: Fri Nov 06, 2009 10:50 pm    Post subject:
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    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Changeman get multiple "Browse C... elixir1986 Compuware & Other Tools 4 Fri Jul 14, 2017 1:48 am
No new posts Include/omit with "ALL" pa... mgl DFSORT/ICETOOL 6 Wed Jun 14, 2017 2:31 pm
No new posts READ A PACKED "NEGATIVE" FI... jdesouza CA Products 3 Tue May 02, 2017 11:43 pm
No new posts RC 20 for Address ISPEXEC "ISRED... pkmurali CLIST & REXX 3 Sun Apr 16, 2017 11:30 pm
No new posts Difference between TWALENG and TWASIZE Arunkumar Chandrasekaran CICS 3 Tue Jan 03, 2017 12:57 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us