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 INNER JOIN vs WHERE

Former Member
0 Likes
14,360

Hello

What is the best programming, putting selection in the inner join or in where clause. Below is some sample code that works but wondering if C~statu='X' would have been better in the Where part of the statement in stead as part of the inner join? Maybe don't need the Where in this select statment just code in the inner joins?

SELECT algnum abdatu btanum btapos atbnum btbpos b~werks

blgort bmatnr bmeins bmaktx bvsolm bvltyp b~vlpla

b~nlpla

INTO TABLE gt_ltak

FROM ltak AS a

INNER JOIN ltap AS b ON blgnum = algnum AND

btanum = atanum

INNER JOIN lrf_wkqu AS c ON clgnum = algnum AND

c~bname = sy-uname AND

cqueue = aqueue AND

c~statu = 'X'

INNER JOIN zis_prog_vars AS d ON d~pgm = 'ZRF_TRANS_03_0100' AND

d~fld = l_priority AND

dval1 = atbpri

WHERE a~lgnum = '170' AND

a~tanum = '0000001399'.

1 ACCEPTED SOLUTION
Read only

Former Member
2,282

Hi,

Herewith the corrected version:


SELECT a~lgnum a~bdatu b~tanum b~tapos a~tbnum b~tbpos b~werks
       b~lgort b~matnr b~meins b~maktx b~vsolm b~vltyp b~vlpla b~nlpla

  INTO TABLE gt_ltak
  FROM ltak AS a

 INNER JOIN ltap AS b ON b~lgnum = a~lgnum AND
                         b~tanum = a~tanum   

 INNER JOIN lrf_wkqu AS c ON c~lgnum = a~lgnum AND
                             c~queue = a~queue AND

 INNER JOIN zis_prog_vars AS d ON d~val1 = a~tbpri

 WHERE a~lgnum = '170'
   AND a~tanum = '0000001399'
   AND c~bname = sy-uname
   AND c~statu = 'X' 
   AND d~pgm = 'ZRF_TRANS_03_0100'
   AND d~fld = l_priority.

Kr,

m.

Hello

What is the best programming, putting selection in the inner join or in where clause. Below is some sample code that works but wondering if C~statu='X' would have been better in the Where part of the statement in stead as part of the inner join? Maybe don't need the Where in this select statment just code in the inner joins?

SELECT algnum abdatu btanum btapos atbnum btbpos b~werks

blgort bmatnr bmeins bmaktx bvsolm bvltyp b~vlpla

b~nlpla

INTO TABLE gt_ltak

FROM ltak AS a

INNER JOIN ltap AS b ON blgnum = algnum AND

btanum = atanum

INNER JOIN lrf_wkqu AS c ON clgnum = algnum AND

c~bname = sy-uname AND

cqueue = aqueue AND

c~statu = 'X'

INNER JOIN zis_prog_vars AS d ON d~pgm = 'ZRF_TRANS_03_0100' AND

d~fld = l_priority AND

dval1 = atbpri

WHERE a~lgnum = '170' AND

a~tanum = '0000001399'.

2 REPLIES 2
Read only

Former Member
0 Likes
2,282

i really would wonder if this select you coded worked at all or is compilable.

In join ONLY conditions that are neccessary to join the tables make sense. rest should be done in the where clause.

Read only

Former Member
2,283

Hi,

Herewith the corrected version:


SELECT a~lgnum a~bdatu b~tanum b~tapos a~tbnum b~tbpos b~werks
       b~lgort b~matnr b~meins b~maktx b~vsolm b~vltyp b~vlpla b~nlpla

  INTO TABLE gt_ltak
  FROM ltak AS a

 INNER JOIN ltap AS b ON b~lgnum = a~lgnum AND
                         b~tanum = a~tanum   

 INNER JOIN lrf_wkqu AS c ON c~lgnum = a~lgnum AND
                             c~queue = a~queue AND

 INNER JOIN zis_prog_vars AS d ON d~val1 = a~tbpri

 WHERE a~lgnum = '170'
   AND a~tanum = '0000001399'
   AND c~bname = sy-uname
   AND c~statu = 'X' 
   AND d~pgm = 'ZRF_TRANS_03_0100'
   AND d~fld = l_priority.

Kr,

m.