‎2008 May 14 5:29 PM
Hi All,
I want to avoid a subquery and created an INNER JOIN, could anyone tell me whether they are the same or different from the given below SQL statment?. The internal table is already defined etc.
Inner Join
SELECT abegda aendda aobjid asobid b~sobid
FROM hrp1001 AS a
INNER JOIN hrp1001 AS b ON aobjid = bobjid AND
b~subty = 'A008' AND
b~sclas = 'P'
INTO TABLE itab_allper
WHERE asubty = 'A003' AND asclas = 'O' and a~endda = '99991231'.
Equivalent in Subquery
SELECT abegda aendda aobjid asobid b~sobid INTO TABLE itab_allper
FROM hrp1001 as a
WHERE a~subty = 'A003' and
a~sclas = 'O' and
a~objid in (SELECT objid FROM HRP1001 as b
WHERE b~subty = 'A008' and
b~sclas = 'O').
Also if I want to display all columns based on objid that are not matching from table b, should I put LEFT OUTTER JOIN instead of INNER JOIN.
Thanks in advance.
Alex.
‎2008 May 15 8:33 AM
Hi Alex,
SELECT abegda aendda aobjid asobid b~sobid
FROM hrp1001 AS a
INNER JOIN hrp1001 AS b ON aobjid = bobjid AND
b~subty = 'A008' AND
b~sclas = 'P'
INTO TABLE itab_allper
WHERE asubty = 'A003' AND asclas = 'O' and a~endda = '99991231'.
In the above query,
b~subty = 'A008' AND
b~sclas = 'P' is not the JOIN condition. So, it would be better if you put those conditions in the WHERE clause, instead, as shown below.
SELECT abegda aendda aobjid asobid b~sobid
FROM hrp1001 AS a
INNER JOIN hrp1001 AS b ON aobjid = bobjid
INTO TABLE itab_allper
WHERE a~subty = 'A003' and
a~sclas = 'O' and
a~endda = '99991231' and
b~subty = 'A008' and
b~sclas = 'P'.
Also ur interpretaion regarding the LEFT OUTER JOIN is correct. In case u want to display all columns based on objid that are not matching from table b, u should use LEFT OUTER JOIN .
Don't forget to reward points, if this is useful.
Pavan.
‎2008 May 15 6:50 AM
Hi Alex Arthur Sam...
Just follow this Inner join syntax
SELECT FLD1 FLD2 FLD3 FLD4 FLD5 INTO CORRESPONDING FIELDS OF TABLE ITAB FROM TABLE1 INNER JOIN TABLE2 ON
TABLE1FLD1 = TABLE2FLD1 INNER JOIN TABLE3 ON TABLE2FLD2 = TABLE3FLD2 INNER JOIN TABL4 ON TABLE3FLD3 = TABLE4FLD3
WHERE FLD1 = 'AA'
Hope this may solve your problem.
Please reward points if found useful.
Thanks and regards,
Rajeshwar.
‎2008 May 15 8:33 AM
Hi Alex,
SELECT abegda aendda aobjid asobid b~sobid
FROM hrp1001 AS a
INNER JOIN hrp1001 AS b ON aobjid = bobjid AND
b~subty = 'A008' AND
b~sclas = 'P'
INTO TABLE itab_allper
WHERE asubty = 'A003' AND asclas = 'O' and a~endda = '99991231'.
In the above query,
b~subty = 'A008' AND
b~sclas = 'P' is not the JOIN condition. So, it would be better if you put those conditions in the WHERE clause, instead, as shown below.
SELECT abegda aendda aobjid asobid b~sobid
FROM hrp1001 AS a
INNER JOIN hrp1001 AS b ON aobjid = bobjid
INTO TABLE itab_allper
WHERE a~subty = 'A003' and
a~sclas = 'O' and
a~endda = '99991231' and
b~subty = 'A008' and
b~sclas = 'P'.
Also ur interpretaion regarding the LEFT OUTER JOIN is correct. In case u want to display all columns based on objid that are not matching from table b, u should use LEFT OUTER JOIN .
Don't forget to reward points, if this is useful.
Pavan.
‎2008 May 15 5:28 PM