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

Nested INNER JOIN

dhiraj_bhatia1
Explorer
0 Likes
1,585

Hi all,

I am joining my three tables using the inner join..

here is code

Select aempid bdeptid

into corr fields of table lt_emp

from ( emp as a INNER JOIN dept as b

ON ( bdeptid = adeptid ) )

INNER JOIN loc as c

ON ( bdeptid = adeptid )

WHERE a~depid EQ lt_dept-deptid.

deptid is present in all three tables but still my lt_emp table is coming empty...

Can anyone suggest me any other way of joining three tables with only one select query..

Thanks n Regards,

Dhiraj B.

2 REPLIES 2
Read only

Former Member
0 Likes
827

Hi

use this.

if it_dept is not initial.

Select aempid bdeptid

into corr fields of table lt_emp

from ( emp as a INNER JOIN dept as b

ON ( bdeptid = adeptid ) )

INNER JOIN loc as c

ON ( cdeptid = bdeptid )

for all entries in it_dept

WHERE a~depid EQ lt_dept-deptid.

endif.

because in your code you are checking deptit from table it_dept in where condition,

which will contain only the last values stored in the header of table it_dept.

this is why i have used for all entries here.

thi for all entries will fetch the data from all the table for all the values matches in table it_dept.

try this and i hope this will work for you.

thanks

LG

Read only

Former Member
0 Likes
827

It should be something like this:

SELECT SINGLE amatnr cwerks

INTO (l_matnr , l_werks)

FROM mara AS a INNER JOIN makt AS b

ON ( amatnr = bmatnr )

INNER JOIN marc AS c

ON ( bmatnr = cmatnr )

WHERE a~matnr EQ l_matnr1.

IF sy-subrc = 0.

ENDIF.

For your query the second on condition is not correct.