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

Sub queries + SQL

Former Member
0 Likes
571

SELECT * FROM SFLIGHT INTO SFLIGHT_WA

WHERE SEATSOCC < SFLIGHT~SEATSMAX

AND EXISTS ( SELECT * FROM SPFLI

WHERE CARRID = SFLIGHT~CARRID

AND CONNID = SFLIGHT~CONNID

AND CITYFROM = 'FRANKFURT'

AND CITYTO = 'NEW YORK' )

AND FLDATE BETWEEN '19990101' AND '19990331'.

ENDSELECT.

plzzz advise when do you use EXISTS how is it more efficient to FOR ALL ENTRIES

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
544

If you use a subquery with the EXISTS operator, the expression is true if the subquery selects at least one line. You can use * in the SELECT clause of subqueries that use EXISTS.

<b>

For all entries.</b>

... FOR ALL ENTRIES IN itab WHERE cond

Effect

SELECT ... FOR ALL ENTRIES IN itab WHERE cond returns the union of the solution sets of all SELECT statements that would result if you wrote a separate statement for each line of the internal table. Duplicates are discarded from the result set. <b><u>If the internal table itab does not contain any entries, the system treats the statement as though there were no WHERE cond condition, and selects all records</u></b> (in the current client).

i hope this will suffice.

even if there are no records in for all entries the select statements fetches values.

But this is not the case with exists.

3 REPLIES 3
Read only

Former Member
0 Likes
544

HI,

effect of exists:

The condition is met for a table entry if the result set of the subquery subquery contains [does not contain] any lines.

it is for data dictionary tables

for all entries is for checking the record in internal table is existing or not.

rgds,

bharat.

Read only

0 Likes
544

" if the result set of the subquery subquery contains [does not contain] any lines. "

Can you please elaborate

Read only

Former Member
0 Likes
545

If you use a subquery with the EXISTS operator, the expression is true if the subquery selects at least one line. You can use * in the SELECT clause of subqueries that use EXISTS.

<b>

For all entries.</b>

... FOR ALL ENTRIES IN itab WHERE cond

Effect

SELECT ... FOR ALL ENTRIES IN itab WHERE cond returns the union of the solution sets of all SELECT statements that would result if you wrote a separate statement for each line of the internal table. Duplicates are discarded from the result set. <b><u>If the internal table itab does not contain any entries, the system treats the statement as though there were no WHERE cond condition, and selects all records</u></b> (in the current client).

i hope this will suffice.

even if there are no records in for all entries the select statements fetches values.

But this is not the case with exists.