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

Select statement for two tables

Former Member
0 Likes
968

Hello mates,

i would like to Join two tables like those below. I only want the values from the table LT who are not in the Table RT.

Am i right doing a Join like this?:

SELECT x

FROM LT

WHERE NOT EXISTS (SELECT y FROM RT Where ..)

and ...

table LT, field xtable RT, field y
ABC/AABC/E
ABC/BABC/E
ABC/CABC/E
ABC/DABC/F
ABC/EABC/F
ABC/FABC/G
ABC/GABC/H

Kind Regards

Emre

1 ACCEPTED SOLUTION
Read only

former_member196331
Active Contributor
0 Likes
925

hi,

select * from Lt into it_Lt (Intenal table of LT)

select * from Rt into it_Rt (Internal table of RT)

Loop at it_LT into wa_lt (work area of Lt).

read table it_RT into Wa_RT with key field x(Right table fieldx) = wa_LT-fieldx(Left table fieldx)

if sy-subrc ne 0.

append it to the new table.

endif.

endloop.

5 REPLIES 5
Read only

sabirshah1
Participant
0 Likes
925

Hi,

You can use Joins Like this

SELECT T1~FIELD1

  T1~FIELD2

  T2~FIELD1

  T2~FIELD2

  INTO TABLE <ITAB>

FROM T1 INNER JOIN T2 ON ( T1~FIELD1 = T2~FIELD )

WHERE T1~FIELD = <SOME VALUE> .

Read only

former_member196331
Active Contributor
0 Likes
926

hi,

select * from Lt into it_Lt (Intenal table of LT)

select * from Rt into it_Rt (Internal table of RT)

Loop at it_LT into wa_lt (work area of Lt).

read table it_RT into Wa_RT with key field x(Right table fieldx) = wa_LT-fieldx(Left table fieldx)

if sy-subrc ne 0.

append it to the new table.

endif.

endloop.

Read only

Tomas_Buryanek
Product and Topic Expert
Product and Topic Expert
0 Likes
925

Yeah, it should work good.


SELECT x

FROM LT

WHERE NOT EXISTS (SELECT * FROM RT

                                        WHERE y = lt~x)

-- Tomas --
Read only

Former Member
0 Likes
925

It's a sub-select not a join.

Rich

Read only

Former Member
0 Likes
925

Thank you all for your replies, I have tried it with the loop over itab and the subselect.

Both work fine. I use the subselect now 

Emre