Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Exists clause in SQL statement...

Former Member
0 Likes
6,802

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,942

This query is going to return a row only when that document exists in VBUK also.

4 REPLIES 4
Read only

Former Member
0 Likes
1,943

This query is going to return a row only when that document exists in VBUK also.

Read only

sarbajitm
Contributor
0 Likes
1,942

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.

Read only

Former Member
0 Likes
1,942

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.

Read only

Former Member
0 Likes
1,942

Hi,

Check this SAP documentation on subqueries.

[http://help.sap.com/saphelp_nw04/helpdata/en/dc/dc7614099b11d295320000e8353423/content.htm]