2007 Nov 28 5:58 AM
hey!!
can anybody tell me how to use iner join with select statement with common fields in the two and other common fields with another two tables.Give an suitable example.
regards,
hey!!
can anybody tell me how to use iner join with select statement with common fields in the two and other common fields with another two tables.Give an suitable example.
regards,
2007 Nov 28 6:01 AM
See example:
DATA: DATE LIKE SFLIGHT-FLDATE,
CARRID LIKE SFLIGHT-CARRID,
CONNID LIKE SFLIGHT-CONNID.
SELECT FCARRID FCONNID F~FLDATE
INTO (CARRID, CONNID, DATE)
FROM SFLIGHT AS F INNER JOIN SPFLI AS P
ON FCARRID = PCARRID
WHERE FCONNID = PCONNID
AND P~CITYFROM = 'FRANKFURT'
AND P~CITYTO = 'NEW YORK'
AND F~FLDATE BETWEEN '20010910' AND '20010920'
AND FSEATSOCC < FSEATSMAX.
WRITE: / DATE, CARRID, CONNID.
ENDSELECT.
Regards
2007 Nov 28 6:01 AM
Hi,
Refer this code for inner join
*--Select query to pick the Billing document Billing date Billing
category Billing type Distribution channel Number of doc condition
Billing item Material Number Plant Referance Subtotal 2 Cost in
document currency and Partner function from table VBRK VBRP and VBPA
using inner join
SELECT a~vbeln "Billing document
a~fkdat "Billing date
a~fktyp "Billing category
a~fkart "Billing type
a~vtweg "Distribution channel
a~knumv "Number of doc condition
b~posnr "Billing item
b~matnr "Material Number
b~werks "Plant
b~vgbel "Referance
b~kzwi2 "Subtotal 2
b~wavwr "Cost in document currency
c~kunnr "Partner function
FROM vbrk AS a
INNER JOIN vbrp AS b
ON avbeln EQ bvbeln
INNER JOIN vbpa AS c
ON bvbeln EQ cvbeln
INTO CORRESPONDING FIELDS OF TABLE it_vbrp
WHERE fkdat IN s_erdat
AND parvw EQ 'ZS'.
IF sy-subrc EQ 0.
*--Sort table by Referance
SORT it_vbrp BY vgbel1.
ENDIF.
but it reduces the performance so better to use FOR ALL ENTRIES
*--Select query to pick the Delivery Material Number Plant
Movement type Subtotal 2 and Quantity from table LIPS
SELECT vbeln "Delivery
matnr "Material Number
werks "Plant
bwart "Movement type
kzwi2 "Subtotal 2
lfimg "Quantity
FROM lips
INTO CORRESPONDING FIELDS OF TABLE it_lips
FOR ALL ENTRIES IN it_vbrp
WHERE vbeln EQ it_vbrp-vgbel1.
IF sy-subrc EQ 0.
*--Sort table by Delivery
SORT it_lips BY vbeln.
ENDIF.
Regards,
Prashant
2007 Nov 28 6:01 AM
refer following querry for inner join on more than two tables...
select a~bukrs
a~anln1
a~anln2
a~anlkl
a~txt50
a~ord41
a~ord42
a~ord43
b~afabe
b~ndabj
b~ndabp
b~kansw
b~knafa
b~kaafa
b~nafag
b~nafap
b~aafam
b~aafag
c~kostl
d~afasl
d~ndjar
d~ndper
into corresponding fields of table gt_master
from ( ( anla as a inner join anlc as b
on abukrs = bbukrs
and aanln1 = banln1
and aanln2 = banln2 )
inner join anlz as c
on abukrs = cbukrs
and aanln1 = canln1
and aanln2 = canln2 )
inner join anlb as d
on abukrs = dbukrs
and aanln1 = danln1
and aanln2 = danln2
where a~bukrs in s_comp
and a~anlkl in s_astcls.
| User | Count |
|---|---|
| 6 | |
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |