View previous topic :: View next topic
|
Author |
Message |
dirceu.alves
New User
Joined: 03 Aug 2005 Posts: 17
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
|