‎2009 Aug 14 7:30 PM
Hello Gurus,
What does the exists clause mean in SQL join below:
SELECT VBAP~VBELN
VBAP~POSNR
VBAP~MATNR
VBAK~VKORG
VBAK~VTWEG
INTO TABLE T_DATA
FROM VBAP
INNER JOIN VBAK
ON VBAPVBELN EQ VBAKVBELN
WHERE VBAP~VBELN IN S_VBELN AND
VBAK~LIFSK IN S_LIFSK AND
EXISTS ( SELECT * FROM VBUK
WHERE VBELN EQ VBAP~VBELN ).
Regards,
Rajesh.
Moderator message - Please press F1 on EXISTS before asking. It's well documented - post locked
Edited by: Rob Burbank on Aug 14, 2009 2:46 PM
‎2009 Aug 14 7:35 PM
This query is going to return a row only when that document exists in VBUK also.
‎2009 Aug 14 7:35 PM
This query is going to return a row only when that document exists in VBUK also.
‎2009 Aug 14 7:39 PM
SELECT VBAP~VBELN
VBAP~POSNR
VBAP~MATNR
VBAK~VKORG
VBAK~VTWEG
INTO TABLE T_DATA
FROM VBAP
INNER JOIN VBAK
ON VBAPVBELN EQ VBAKVBELN
WHERE VBAP~VBELN IN S_VBELN AND
VBAK~LIFSK IN S_LIFSK AND
EXISTS ( SELECT * FROM VBUK
WHERE VBELN EQ VBAP~VBELN ).
I think this EXISTS operator just check whether the subquery returning any row for the current vbeln.IF yes ,then the joining output will be added to the resultset otherwise not.
But honestly I'm not sure so carry on RnD for your own clarification and also help us to learn this.
Regards.
Sarbajit.
‎2009 Aug 14 7:42 PM
Hi,
The EXISTS keyword basically works when the subquery returns at least one row. If the sub query returns any resultant dataset, then the outer query executes. Otherwise, the outer query does not execute.
An F1 on the keyword will give you a clear picture.
‎2009 Aug 14 7:44 PM
Hi,
Check this SAP documentation on subqueries.
[http://help.sap.com/saphelp_nw04/helpdata/en/dc/dc7614099b11d295320000e8353423/content.htm]