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

INNER JOIN does not support OR operator

Former Member
0 Likes
431

Hi all,

I want to use inner join with two database tables where the field from the first table can be compare to two fields from the second table.

The code as follow is syntactically not correct:

SELECT ...
INTO TABLE it_tab
FROM ZTABLE1 as a
INNER JOIN ZTABLE2 as b
  ON a~PK1 = b~F1 OR a~PK1 = b~F2. "Not work

My work-around is using another temp table with same structure as it_tab. Select data two times then moves from the temp table to the it_tab table.

Please suggest me on how to use INNER JOIN without using another temp table.

Thanks,

Khanh

1 ACCEPTED SOLUTION
Read only

rainer_hbenthal
Active Contributor
0 Likes
364

The syntax of the join conditions join_cond is the same as that of the sql_cond conditions after the addition WHERE, with the following differences:

At least one comparison must be specified after ON.

Individual comparisons may be joined using AND only.

Make two selects adding the results in the second select to the internal table

2 REPLIES 2
Read only

rainer_hbenthal
Active Contributor
0 Likes
365

The syntax of the join conditions join_cond is the same as that of the sql_cond conditions after the addition WHERE, with the following differences:

At least one comparison must be specified after ON.

Individual comparisons may be joined using AND only.

Make two selects adding the results in the second select to the internal table

Read only

Former Member
0 Likes
364

have you pressed F1 on join?

>Individual comparisons may be joined using AND only .

so i hope its clear that you cannot use the OR condition.

better fetch with both conditions 2 times or use FOR ALL ENTRIES

first select from ztable1 into table itab1.

then

select * from ztabl2 into table itab2
         for all entries in itab1
         where (f1 = itab1-f1 or f1 = itab-f2) .

any ways using OR means it will separate the select into two.