How to use INNER JOIN in such case
when i program as below[CASE1]. the code is able to active.
CASE1:
==========================
DATA: WK_BUKRS LIKE T001-BUKRS,
WK_BUTXT LIKE T001-BUTXT,
WK_TABLE(4) TYPE C VALUE 'T001'.
START-OF-SELECTION.
WK_BUKRS = 'DECN'.
PERFORM GET_BUTXT USING WK_BUKRS WK_TABLE
CHANGING WK_BUTXT.
WRITE: WK_BUTXT.
FORM GET_BUTXT USING I_BUKRS LIKE T001-BUKRS
I_TABLE
CHANGING O_BUTXT LIKE T001-BUTXT.
SELECT SINGLE BUTXT
INTO O_BUTXT
FROM (I_TABLE)
WHERE BUKRS = I_BUKRS.
ENDFORM.
===========================
but when I need to INNER JOIN another table [CASE2]
CASE2:
=======================
DATA: WK_BUKRS LIKE T001-BUKRS,
WK_BUTXT LIKE T001-BUTXT,
WK_TABLE(4) TYPE C VALUE 'T001'.
START-OF-SELECTION.
WK_BUKRS = 'DECN'.
PERFORM GET_BUTXT USING WK_BUKRS WK_TABLE
CHANGING WK_BUTXT.
WRITE: WK_BUTXT.
FORM GET_BUTXT USING I_BUKRS LIKE T001-BUKRS
I_TABLE
CHANGING O_BUTXT LIKE T001-BUTXT.
SELECT SINGLE BUTXT
INTO O_BUTXT
FROM (I_TABLE) AS G INNER JOIN BKPF AS H
ON GBUKRS = HBUKRS
WHERE G~BUKRS = I_BUKRS.
ENDFORM.
=================================
Syntax error:
Wrong expression "INNER" in FROM clause. WHERE condition.
Can anybody help me to solve the problem.
My requirement is to use INNER JOIN with variable table
hi slam,
chk this sample code.
hi,
table emp
empno name
a sasi
b xxx
c yyy
table sal
empno salary
a 1000
b 2000
Inner join
select eempno ename
s~sal
into table int_table
from emp as e
inner join sal as s
on
eempno = sempno.
if you made inner join between table a and b by emp no
the selection retrives only if the condition satisfy the output will be
a sasi 1000
b xxx 2000
rgds
anver
if hlped mark points
Message was edited by: Anversha s
Similar Messages
-
How to use Inner join of table as Source in Merge statement in SQL
Hi All,
I am trying to make source as multiple tables output using Join while coding there is no any syntax error but when i am executing this statement is giving following error
Following is the query
Merge Into EmpDept Target
Using (select E.Address,e.Design,e.EmailId,e.EmpId,e.Ename,e.ManagerId, e.Salary,D.DeptId,D.DeptName,D.Location from Employee E Inner join Dept D on E.DeptId=D.DeptId )As Source (Address,Design,EmailId,EmpId,EName,ManagerId,Salary,DeptId,DeptName,Location)
On Source.EmpId=Target.EmpId
when not matched then
Insert (Target.Address,Target.Design,Target.EmailId,Target.EmpId,Target.Ename,Target.ManagerId, Target.Salary,Target.DeptId,Target.DeptName,Target.Location)
values
(Address,Design,EmailId,EmpId,EName,ManagerId, Salary,DeptId,DeptName,Location)
When matched then
Update set Target.Address = Source.Address ,Target.Design = Source.Design,Target.EmailId = Source.EmailId ,Target.Ename = Source.Ename ,Target.ManagerId = Source.ManagerId , Target.Salary = Source.Salary ,Target.DeptId = Source.DeptId ,Target.DeptName = Source.DeptName ,Target.Location = Source.Location;
This is error while executing the above merge statement
The insert column list used in the MERGE statement cannot contain multi-part identifiers. Use single part identifiers instead.
Please suggest me where i am wrong..
Niraj SevalkarMERGE INTO EmpDept Target
Using (SELECT E.Address,
e.Design,
e.EmailId,
e.EmpId,
e.Ename,
e.ManagerId,
e.Salary,
D.DeptId,
D.DeptName,
D.Location
FROM Employee E
INNER JOIN Dept D
ON E.DeptId = D.DeptId) AS Source (Address, Design, EmailId, EmpId, EName, ManagerId, Salary, DeptId, DeptName, Location)
ON Source.EmpId = Target.EmpId
WHEN NOT matched THEN
INSERT (Address,
Design,
EmailId,
EmpId,
Ename,
ManagerId,
Salary,
DeptId,
DeptName,
Location)
VALUES (Address,
Design,
EmailId,
EmpId,
EName,
ManagerId,
Salary,
DeptId,
DeptName,
Location)
WHEN matched THEN
UPDATE SET Address = Source.Address,
Design = Source.Design,
EmailId = Source.EmailId,
Ename = Source.Ename,
ManagerId = Source.ManagerId,
Salary = Source.Salary,
DeptId = Source.DeptId,
DeptName = Source.DeptName,
Location = Source.Location; -
How to use Inner Join for these 4 table's
Hi Guys,
My Requirement is i have to get the data into the final Internal table whose structure is like this (BWKEY type MBEW-BWKEY,
MATNR type MBEW-MATNR,
MAKTX type MAKT-MAKTX,
BWTTY type MBEW-BWTTY,
BWTAR type MBEW-BWTAR,
MEINS type MARA-MEINS,
BKLAS type MBEW-BKLAS,
VPRSV type MBEW-VPRSV,
STPRS type MBEW-STPRS,
PEINH type MBEW-PEINH,
CRCY(3) type c,
LBKUM type MBEW-LBKUM,
SALK3 type MBEW-SALK3,
LAEPR type MBEW-LAEPR,
J_3ADEFSI type MARC-J_3ADEFSI,
J_4kDEFSC type MARC-J_4kDEFSC,
SCLAS type MARA-/AFS/SCLAS,
EKALR type MBEW-EKALR,
HKMAT type MBEW-HKMAT,
HRKFT type MBEW-HRKFT,
KOSGR type MBEW-KOSGR,
PRCTR type MARC-PRCTR,
MMSTA type MARC-MMSTA,
SOBSK type MARC-SOBSK,
PPRDL type MBEW-PPRDL,
LPLPR type MBEW-LPLPR,
PPRDZ type MBEW-PPRDZ,
ZPLPR type MBEW-ZPLPR)
from 4 table's MBEW , MARA MAKT and MARC.
Can anybody provide the logci for this based on the below requirement
"Go to table MBEW with material number, plant and valuation type; fetch the information laid out in output format. There are some fields which need to come from tables MARC, MARA and MAKT. The common criterion is material number across these tables.
MBEW-MATNR = MARC-MATNR
MBEW-MATNR = MARA-MATNR
MBEW-MATNR = MAKT-MATNR
Thanks,
Gopi.Hello Gopi,
I did not have system now and just written in notepad..
types : begin of ty_mbew ,
MATNR type MBEW-MATNR,
BWTTY type MBEW-BWTTY,
BWTAR type MBEW-BWTAR,
MEINS type MARA-MEINS,
BKLAS type MBEW-BKLAS,
VPRSV type MBEW-VPRSV,
STPRS type MBEW-STPRS,
PEINH type MBEW-PEINH,
CRCY(3) type c, " What is this field ,i did not include in join
LBKUM type MBEW-LBKUM,
SALK3 type MBEW-SALK3,
LAEPR type MBEW-LAEPR,
J_3ADEFSI type MARC-J_3ADEFSI,
J_4kDEFSC type MARC-J_4kDEFSC,
SCLAS type MARA-/AFS/SCLAS,
EKALR type MBEW-EKALR,
HKMAT type MBEW-HKMAT,
HRKFT type MBEW-HRKFT,
KOSGR type MBEW-KOSGR,
PRCTR type MARC-PRCTR,
MMSTA type MARC-MMSTA,
SOBSK type MARC-SOBSK,
PPRDL type MBEW-PPRDL,
LPLPR type MBEW-LPLPR,
PPRDZ type MBEW-PPRDZ,
ZPLPR type MBEW-ZPLPR,
end of ty_mbew.
types : begin of ty_makt ,
matnr type makt-maktx,
MAKTX type MAKT-MAKTX,
end of ty_makt.
types : begin of ty_final ,
MATNR type MBEW-MATNR,
MAKTX type MAKT-MAKTX,
BWTTY type MBEW-BWTTY,
BWTAR type MBEW-BWTAR,
MEINS type MARA-MEINS,
BKLAS type MBEW-BKLAS,
VPRSV type MBEW-VPRSV,
STPRS type MBEW-STPRS,
PEINH type MBEW-PEINH,
CRCY(3) type c,
LBKUM type MBEW-LBKUM,
SALK3 type MBEW-SALK3,
LAEPR type MBEW-LAEPR,
J_3ADEFSI type MARC-J_3ADEFSI,
J_4kDEFSC type MARC-J_4kDEFSC,
SCLAS type MARA-/AFS/SCLAS,
EKALR type MBEW-EKALR,
HKMAT type MBEW-HKMAT,
HRKFT type MBEW-HRKFT,
KOSGR type MBEW-KOSGR,
PRCTR type MARC-PRCTR,
MMSTA type MARC-MMSTA,
SOBSK type MARC-SOBSK,
PPRDL type MBEW-PPRDL,
LPLPR type MBEW-LPLPR,
PPRDZ type MBEW-PPRDZ,
ZPLPR type MBEW-ZPLPR,
end of ty_final.
Internal tables
data :i_mbew type standard table of ty_mbew,
i_makt type standard table of ty_makt,
i_final type standard table of ty_final.
Work Areas
data : wa_mbew like line of i_mbew,
wa_makt like line of i_makt,
wa_final like line of i_final.
start-of-selection.
get the data from MBEW,MARA,MARC Table
select aMATNR aBWTTY
aBWTAR bMEINS
aBKLAS aVPRSV
aSTPRS aPEINH
*CRCY(3) type c,
aLBKUM aSALK3 a~LAEPR
c~J_3ADEFSI type MARC-J_3ADEFSI,
c~J_4kDEFSC type MARC-J_4kDEFSC,
b~SCLAS type MARA-/AFS/SCLAS,
aEKALR aHKMAT
aHRKFT aKOSGR
cPRCTR cMMSTA
cSOBSK aPPRDL
aLPLPR aPPRDZ
a~ZPLPR into corresponding fields of table i_mbew
from mbew as a inner join mara as b on bmatnr = amatnr
inner join marc as c on cmatnr = amatnr.
if sy-subrc eq 0.
select matnr maktx from makt into table i_makt
for all entries in i_mbew
where matnr = i_mbew-matnr
and spras = sy-langu.
endif.
loop at i_mbew into wa_mbew.
read the data from MAKT Table
read table i_makt into wa_makt with key matnr = wa_mbew-matnr.
if sy-subrc eq 0.
move-corresponding wa_mbew to wa_final.
move wa_makt-maktx to wa_final-maktx.
append wa_final to i_final.
endif.
endloop.
Thanks
Seshu -
How to use inner joins for 4 0r 5 tables
Hai Experts,
plz check my code, n plz help to inner join all the tables
TYPES : BEGIN OF ITAB,
EBELN TYPE EKKO-EBELN, "P.O.NUMBER
AEDAT TYPE EKKO-AEDAT, "DATE
BPRME TYPE EKPO-BPRME, "UNIT PRICE
MENGE TYPE EKPO-MENGE, "Purchase order quantity
WERKS TYPE EKPO-WERKS, "PLANT
BRTWR TYPE EKPO-BRTWR, "Gross order value in PO
STRAS TYPE LFA1-STRAS, "House number and street
LIFNR TYPE LFA1-LIFNR, "VENDOR NO
NAME1 TYPE LFA1-NAME1, "V NAME
ORT01 TYPE LFA1-ORT01, "CITY
LAND1 TYPE LFA1-LAND1, "LAND
PSTLZ TYPE LFA1-PSTLZ, "POSTAL CODE
MAKTX TYPE MAKT-MAKTX, "DESCRIPTION
END OF ITAB.
<b>and i got stucked here:</b>
<u></u>
SELECT EKKO~EBELN
EKKO~AEDAT
EKPO~BPRME
EKPO~MENGE
EKPO~WERKS
EKPO~BRTWR
LFA1~LIFNR
LFA1~STRAS
LFA1~NAME1
LFA1~ORT01
LFA1~LAND1
LFA1~PSTLZ
MAKT~MAKTX
INTO TABLE ITAB
FROM EKKO
INNER JOIN EKPO LFA1 T001W MAKT
ON EKKOEBELN = EKPOEBELN
EKKO~EBELN
WHERE EKKO~EBELN IN S_EBELN.hi Rajesh,
you have to join the tables one by one:
SELECT ekko~ebeln
ekko~aedat
ekpo~bprme
ekpo~menge
ekpo~werks
ekpo~brtwr
lfa1~lifnr
lfa1~stras
lfa1~name1
lfa1~ort01
lfa1~land1
lfa1~pstlz
makt~maktx
INTO TABLE itab
FROM ekko AS ekko
INNER JOIN ekpo AS ekpo
ON ekkoebeln EQ ekpoebeln
INNER JOIN lfa1 AS lfa1
ON ekkolifnr EQ lfa1lifnr
INNER JOIN t001w AS t001w
ON ekpowerks EQ t001wwerks
INNER JOIN makt AS makt
ON ekpomatnr EQ MAKTmatnr
WHERE ekko~ebeln IN s_ebeln.
This is the complete SELECT. BUT! The performance will be much better if you take out T001W and MAKT from the INNER JOIN. Do select on these tables in separate steps and merge the internal tables afterwards.
hope this helps
ec -
How to use keyfigure selection in such case
Hi expert,
Here is the case, data like below:
material plant ordqty
A p1 100
A p2 50
B p1 30
I want a new keyfigure to show
material plant ordqty ordqty(all plant)
A p1 100 150
A p2 50 150
B p1 30 30
Could you please give me some idea, thank you in advance.
Edited by: YAODAN on Oct 9, 2011 9:30 AMHi
Please check if the below solution works for you.
1. Have material and plant in rows
2. Put ORDQTY in Key Figure
3. Create a new Formula Key Figure . Use the available function SUMCT to generate Sum of all plants for a particular material.
> SUMCT (ORDQTY)
SUMCT is available under Data Function folder.
Regards
Anindya -
How to do inner join ,outer join, left join ,right join by using infoset
how to do inner join ,outer join, left join ,right join by using infoset
Hi
If you want to make join ,outer join, left join ,right join then its possible if you are using ODS or direct infoobject (In BW3.5) and if you are using BI7.0 then you also make join ,outer join, left join ,right join with Cube also.
For making join ,outer join, left join ,right join in infosets you just select your info provider then right click on your infoarea from context menu select info set after doing this one pop-up opens here u define your infoset technical name and give either ODS object name of infoobject name.
After doing this next screen opens in right hand side your selectes ODS or infoobject shows in graphical format .
and left hand side it shows one menu bar here you can select another ODS or infoobject for making join ,outer join, left join ,right join .just click on ODS button in menu bar and select ODS drag your selected ODS from Left to right after doing this your selected ODS shown in right hand side window in graphical format you just now after doing this you are able to make join ,outer join, left join ,right join for this first you select field from one ods and drag a line from 1 ods to second ods after doing this one arrow is created from one ods to another ods just right click on arrow and make join ,outer join, left join ,right join in to your ODS.
I think its clear how we can we make join ,outer join, left join ,right join in infoset.If you have any further query then welcome.
Assign Points...............
Thanks and regards
Ankit modi -
I need to delete records from a table using inner join from other tables. See below for the table structure and records.
CREATE TABLE STUDENT (ROLL_NO NUMBER(10),NAME VARCHAR2(100),DEPT_NO NUMBER(10),JOIN_DATE DATE);
CREATE TABLE DEPART (DEPT_NO NUMBER(10), DEPT_NAME VARCHAR2(100));
CREATE TABLE ACTIVE_DEPT (DEPT_NO NUMBER(10), IS_ACTIVE VARCHAR2(1));
INSERT INTO STUDENT (ROLL_NO,NAME,DEPT_NO,JOIN_DATE) VALUES(1,'SAM',10,SYSDATE-10);
INSERT INTO STUDENT (ROLL_NO,NAME,DEPT_NO,JOIN_DATE) VALUES(2,'ALEX',10,SYSDATE -10);
INSERT INTO STUDENT (ROLL_NO,NAME,DEPT_NO,JOIN_DATE) VALUES(3,'FRANK',20,SYSDATE -10);
INSERT INTO STUDENT (ROLL_NO,NAME,DEPT_NO,JOIN_DATE) VALUES(4,'WAYNE',20,SYSDATE+1);
INSERT INTO STUDENT (ROLL_NO,NAME,DEPT_NO,JOIN_DATE) VALUES(5,'KRUL',30,SYSDATE -10);
INSERT INTO STUDENT (ROLL_NO,NAME,DEPT_NO,JOIN_DATE) VALUES(6,'ALICE',40,SYSDATE -10);
INSERT INTO DEPART (DEPT_NO,DEPT_NAME) VALUES (10,'DEPT1');
INSERT INTO DEPART (DEPT_NO,DEPT_NAME) VALUES (20,'DEPT2');
INSERT INTO DEPART (DEPT_NO,DEPT_NAME) VALUES (30,'DEPT3');
INSERT INTO ACTIVE_DEPT (DEPT_NO,IS_ACTIVE) VALUES (10,'Y');
INSERT INTO ACTIVE_DEPT (DEPT_NO,IS_ACTIVE) VALUES (20,'N');
INSERT INTO ACTIVE_DEPT (DEPT_NO,IS_ACTIVE) VALUES (30,'Y');
DELETE FROM STUDENT WHERE (STUDENT.DEPT_NO) IN (SELECT D.dept_no FROM DEPART D,ACTIVE_DEPT AD WHERE D.DEPT_NO = AD.DEPT_NO AND AD.IS_ACTIVE = 'N');The above delete query will delete two records from the STUDENT table. Now i want to include another condition say, join_date should be a past date (join_date < trunc(sysdate)).
How to include this condition in the above delete statement. I know i can do this using a subquery but i wont prefer that option. Basically i don't have much idea about join in delete statements.
Please help.Is this you need ?
DELETE FROM student WHERE join_date < TRUNC(SYSDATE)
AND student.dept_no IN (SELECT D.dept_no
FROM depart d,active_dept ad
WHERE d.dept_no = ad.dept_no AND ad.is_active = 'N');Only one record is deleted. -> 3,'FRANK',20,SYSDATE -10
>
Balaji wrote:
Yes. But here we are getting the dept_no from the sub query, is there a better way to achieve this without sub query?
>
As far I know you need to have sub query in this case.
You can close this thread if answered. If you have any further queries please post it so that someone can help you.
Edited by: Lokanath Giri on २० मार्च, २०१२ ५:०५ अपराह्न -
How to use outer join condition in my below query.
Hi All,
How to use outer join condition in my below query.
In the table APPS_JP.GEDIS_OFFER_HEADER goh I have more records
in the table APPS_JP.GEDIS_ORDER_BUILDS gob I have less number of records.
I want all the records from APPS_JP.GEDIS_OFFER_HEADER goh
including other conditions.
I have tried goh.OFFER_NO=gob.OFFER_NO(+) but same result.
[code]SELECT GOH.ORIG_SYSTEM,
gsp.USER_NAME,
goh.ORDER_NO,
goh.OMEGA_ORDER_NUMBER,
goh.ORDER_TYPE,
gc.CUSTOMER_ID,
gc.OMEGA_CUSTOMER_NUMBER,
CASE WHEN gc.PRIVATE = 'N' THEN gc.CUSTOMER_NAME ELSE '' END
AS COMPANY_NAME,
goh.ORDER_STATUS,
goh.TOTAL_SELLING_PRICE,
goh.TOTAL_MARGIN,
ga1.ADDRESS1
|| ','
|| ga1.ADDRESS2
|| ','
|| ga1.ADDRESS3
|| ','
|| ga1.POSTAL_CODE
|| ','
|| ga1.CITY
AS SHIPPING_ADDRESS,
ga2.ADDRESS1
|| ','
|| ga2.ADDRESS2
|| ','
|| ga2.ADDRESS3
|| ','
|| ga2.POSTAL_CODE
|| ','
|| ga2.CITY
AS BILLING_ADDRESS,
ga.ADDRESS_ID,
gol.DESCRIPTION,
APPS_JP.TZ.to_local_date (goh.OFFER_DATE, goh.OFFER_DATE_UTC)
AS OFFER_DATE,
gc.LEVEL_8,
goh.NO_OF_BUILDS,
gob.SFDC_ID,
goh.PURCHASE_ORDER_NO AS PO,
gc1.CUSTOMER_NAME AS END_USAGE,
gol.LOB,
goh.TOTAL_MARGIN_PCT,
goh.TOTAL_DISCOUNT,
goh.TOTAL_DISCOUNT_PCT
FROM APPS_JP.GEDIS_OFFER_HEADER goh,
APPS_JP.GEDIS_ORDER_BUILDS gob,
APPS_JP.GEDIS_ORDER_LINES gol,
APPS_JP.GEDIS_OFFER_RELATED_CUSTOMER gorc,
APPS_JP.GEDIS_OFFER_RELATED_CUSTOMER ship,
APPS_JP.GEDIS_OFFER_RELATED_CUSTOMER bill,
APPS_JP.GEDIS_CUSTOMER gc,
APPS_JP.GEDIS_CUSTOMER gc1,
APPS_JP.GEDIS_CONTACT gct,
APPS_JP.GEDIS_ADDRESS ga,
APPS_JP.GEDIS_ADDRESS_NORM ga1,
APPS_JP.GEDIS_ADDRESS_NORM ga2,
(SELECT DISTINCT SALESPERSON_ID, USER_NAME
FROM APPS_JP.GEDIS_SALESPERSON
WHERE SALESPERSON_ID IN
(SELECT TO_NUMBER (COLUMN_VALUE) AS SALESPERSON_ID
FROM TABLE (APPS_GLOBAL.SplitString ('337309'))))
gsp
WHERE goh.ORDER_NO <> 0
AND goh.OFFER_NO <> 0
AND goh.OFFER_NO=gol.OFFER_NO
AND gol.BUILD_NO = 1
AND gol.LINE_NO = 1
AND goh.OFFER_NO=gob.OFFER_NO
AND gob.BUILD_NO = 1
AND goh.OFFER_NO = gorc.OFFER_NO
AND gct.CONTACT_ID = gorc.CONTACT_ID
AND ga.CUSTOMER_ID = gc.CUSTOMER_ID
AND ga.PRIMARY = 'Y'
AND goh.LEAD_SALESPERSON=gsp.SALESPERSON_ID
AND goh.OFFER_NO = ship.OFFER_NO
AND ship.RELATION_TYPE = 'SHIP'
AND ga1.ADDRESS_ID = ship.ADDRESS_ID
AND ga1.CUSTOMER_ID = gc1.CUSTOMER_ID
AND goh.OFFER_NO = bill.OFFER_NO
AND bill.RELATION_TYPE = 'BILL'
AND ga2.ADDRESS_ID = bill.ADDRESS_ID
AND goh.OFFER_DATE BETWEEN APPS_JP.TZ.LOCAL_TO_DB_DATE (
SYSDATE - 30
AND APPS_JP.TZ.LOCAL_TO_DB_DATE (SYSDATE)
AND gorc.RELATION_TYPE = 'BASE'
AND gorc.CUSTOMER_ID = gc.CUSTOMER_ID
AND goh.SALES_CHANNEL = gc.SALES_CHANNEL
AND gc.SALES_CHANNEL = 'SMB'
AND goh.LEAD_SALESPERSON IN (goh.CREATED_BY, goh.LEAD_SALESPERSON)
ORDER BY goh.OFFER_NO;[/code]
Please help me how to use this outer join condition.
Thanks in advance.Hi,
If you want all the rows from goh, then you don't want any conditions like goh.OFFER_NO <> 0.
Make all the joins to goh outer joins, and make all conditions that apply to any tables joined to goh (or to tables joined to them) part of the join condition, like this:
FROM APPS_JP.GEDIS_OFFER_HEADER goh
LEFT OUTER JOIN APPS_JP.GEDIS_ORDER_BUILDS gob ON gob.OFFER_NO = goh.OFFER_NO
AND gob.BUILD_NO = 1
LEFT OUTER JOIN APPS_JP.GEDIS_ORDER_LINES gol ON gol.OFFER_NO = goh.OFFER_NO
AND gol.BUILD_NO = 1
AND gol.LINE_NO = 1
LEFT OUTER JOIN APPS_JP.GEDIS_OFFER_RELATED_CUSTOMER
gorc ...
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
Simplify the problem as much as possible. For example, do you really need all those tables to show what the problem is? Of course, you need them in tyour real query, but if you understand a solution that only involves 4 or 5 tables, you'll know how to apply it to any number of tables.
Explain, using specific examples, how you get those results from that data.Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
See the forum FAQ https://forums.oracle.com/message/9362002#9362002 -
How to use outer join on 3 tables
how to use outer join on 3 tables
say tables are mkpf,lips and vbrp
mkpf-xblnr = lips-vbeln
lips-vbeln = vbrp-vgbelrefer following querry
select a~bukrs
a~anln1
a~ord42
a~ord43
b~afabe
b~ndabj
b~kaafa
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. -
How to use a CTE in a CASE statement?
Hi everyone,
I'm trying to use a CTE in a CASE statement and getting error. In fact, I'm not sure how to use a CTE in this case and this is the first time I'm using a CTE. I managed to build a CTE successfully but, failed to incorporate it in the CASE statement.
SELECT wbs,
MIN(srt),
MAX(srt)
CASE ust
WHEN
WITH CTE AS
SELECT p_id + p_name + ps_name AS colg, p_id
FROM pd_info
WHERE s_desc = 'warehouse'
OR p_desc = 'Originated from warehouse'
OR p_desc = 'Originated from a partner store'
SELECT colg FROM CTE
WHERE cte.colg IN (SELECT p_id + p_name + ps_name AS c
omb from pd_info)
OR cte.p_id = 'xxxxxxxx' THEN 'invalid'
ELSE 'valid'
END,
p_name,
sub_name,
ps_name,
FROM pd_info;
Could experts here please help me?
Thank you,
Bangaaram
Known is a DROP, Unknown is an OCEAN.With the help from some experts, I've figured out that CTE doesn't work in this case. Here are the queries that I'm using for the above. Either of them is working good so far.
SELECT Wbs
, MIN ( Srt )
, MAX ( Srt )
, CASE
WHEN S_Desc = 'warehouse'
OR P_Desc = 'Originated from warehouse'
OR P_Desc = 'Originated from a partner store'
OR P_Id = 'xxxxxxxx'
THEN 'invalid'
ELSE 'valid'
END AS Ust
, P_Name
, Sub_Name
, Ps_Name
FROM Pd_Info
GROUP BY Wbs
, CASE
WHEN S_Desc = 'warehouse'
OR P_Desc = 'Originated from warehouse'
OR P_Desc = 'Originated from a partner store'
OR P_Id = 'xxxxxxxx'
THEN 'invalid'
ELSE 'valid'
END
, P_Name
, Sub_Name
, Ps_Name;
SELECT wbs,
MIN(srt),
MAX(srt)
CASE
WHEN cte.p_id = 'xxxxxxxx'
or exists
(select *
from pd_info p2
WHERE (s_desc = 'warehouse'
OR p_desc = 'Originated from warehouse'
OR p_desc = 'Originated from a partner store' )
and p2.p_id = p1.p_id and p2.p_name = p1.p_name and p2.ps_name = p1.ps_name
THEN 'invalid'
ELSE 'valid'
END ust,
p_name,
sub_name,
ps_name,
FROM pd_info p1;
Thank you,
Bangaaram
Known is a DROP, Unknown is an OCEAN. -
Select querry using inner join
Hi Friends,
I need to fetch data from two tables, I used inner join but I am not able to fetch the data in some fields can any one tell me what is wrong in this select querry.
SELECT but000~partner
but000~name_org1
but000~name_first
but000~name_last
but000~bpext
FROM but000 INNER JOIN dfkkop ON but000partner = dfkkopgpart
INTO table lt_but000
WHERE but000~partner IN so_part
AND dfkkop~faedn IN so_faedn.
Thanx in advance,
Parvezhi Lutin,
SELECT but000~partner
but000~name_org1
but000~name_first
but000~name_last
but000~bpext
FROM but000 INNER JOIN dfkkop ON but000partner = dfkkopgpart <------check this condition,it has to *satisfy both table
INTO table lt_but000
WHERE but000~partner IN so_part
AND dfkkop~faedn IN so_faedn.
Regards,
siva
Message was edited by:
SivaKumar -
How to use BKPF and BSEG without using inner join
Hi,
can anybody plz tell me the logic about how to complete the report without inner joining bkpf and bseg.Is this report can be really be made by using only bseg,bkpf ?
*selection-criteria .
BKPF-USNAM
BKPF-CPUDT
BKPF-BUDAT
BKPF-GJAHR
BKPF-BUKRS
BKPF-BELNR
BSEG-SAKNR
BSEG-LIFNR
BSEG-KUNNR
BSEG-ZUONR
BSEG-SGTXT
Output fields required.
BKPF-BUKRS
BKPF-BELNR
BKPF-GJAHR
BKPF-MONAT
BKPF-BLART
BKPF-CPUDT
BKPF-BLDAT
BKPF-BUDAT
BKPF-USNAM
BKPF-XBLNR
BKPF-STBLG
BKPF-BKTXT
BKPF-WAERS
BKPF-KURSF
BSEG-BUZEI
BSEG-BSCHL
BSEG-KOART
BSEG-UMSKZ
BSEG-SHKZG
BSEG-MWSKZ
BSEG-PSWBT
BSEG-PSWSL
BSEG-DMBTR
BSEG-SAKNR
BSEG-HKONT
BSEG-KOSTL
BSEG-KUNNR
BSEG-VBELN
BSEG-LIFNR
BSEG-ANLN1
BSEG-ANLN2
BSEG-AUFNR
BSEG-MATNR
BSEG-MENGE
BSEG-MEINS
BSEG-ZUONR
BSEG-SGTXT
Thanks,
Rahman
Moderator Message: Please search before posting your question. Thread locked.
Edited by: Suhas Saha on Jan 31, 2012 3:07 PMQuick question - what's preventing your from using built-in functions?
I suggest mapping your Time Dim to a standard Time Dim and work with it - you'll save a lot more time. You'd even need this table if you wanted to work around Todate/AGO.
It is possible to model this functionality w/o functions, but it'll be time consuming task, similar to using Time Series Wizard in Siebel Analytics. You'll need to build aliases and views along with some complex joins (such as TIME.KEY=TIME.KEY-365), introduce a bunch of variables to control. Also, you might not get much flexibility in terms of years. For each year, you'd need an alias table. (TIME_DIM_PY). -
How to use multipule join in update stmt
hi,
i have a query in mssql i want to translate it using oracle 11g r2 latest sysntex
UPDATE trips
SET locations = trips.city + ', ' + poi.city
FROM trips INNER JOIN poi
ON poi.trip_guid = trips.guid
where trips.trip_guid =1
UPDATE trips t
SET locations = t.city + ', ' + p.city
FROM poi p
ON p.trip_guid = t.guid
where t.trip_guid =1
please tel me how i can write it in oracel 11g r2
i also show there is mearge statmet is it sql or plsql
yours sincerelyupdate trips t
set locations = t.city || ', ' ||
(select p.city || e.allow
from poi p
, emp e
where p.trip_guid = t.guid AND e.id = t.id
update trips t
set locations = t.city || ', ' ||
(select p.city || e.allow
from poi p
left join emp e on e.id = t.id
where p.trip_guid = t.guid
1)are these both query same and correct if i want to upate all rows.
2) some body said following two query are different
if there is any theory then pls tel me. because i have to use rownum<2 to get the top most row rather than distinct
in few cases
at some other places.
-- works but look at the number of rows updated
UPDATE test t
SET (tablespace_name, extent_management) = (
SELECT DISTINCT u.tablespace_name, u.extent_management
FROM user_tables a, user_tablespaces u
WHERE t.table_name = a.table_name
AND a.tablespace_name = u.tablespace_name
AND t.table_name LIKE '%A%');
-- works properly
UPDATE test t
SET (tablespace_name, extent_management) = (
SELECT DISTINCT (u.tablespace_name, u.extent_management)
FROM user_tables a, user_tablespaces u
WHERE t.table_name = a.table_name
AND a.tablespace_name = u.tablespace_name)
WHERE t.table_name LIKE '%A%';
yours sincerely
Edited by: 944768 on Feb 20, 2013 5:36 AM
Edited by: 944768 on Feb 20, 2013 5:39 AM -
For All Entries is NOT better than INNER JOIN in most cases
I quote from Siegfried Boes' excellent post here: Will writing an inner join be better or creating a view?
For all the FOR ALL ENTRIES lovers ... there is no proof for these reappearing recommendation.
There is nearly nobody who receives forum points, who recommends FOR ALL ENTRIES instead of Joins. What is the reason ???
It is easier to prove the opposite. A Join is a nested loop inside the database, a FOR ALL ENTRIES is partly outside of the database. FOR ALL ENTRIES works in blocks, joins on totals.
FOR ALL ENTRIES are not recommded on really large tables, because the chances are too high that
too many records are transferred.
People prefer FOR ALL ENTRIES, because JOINs are not so easy to understand. Joins can go wrong, but with a bit of understanding they can be fixed.
Some Joins are slow and can not be fixed, but then the FOR ALL ENTRIES would be extremely slow.
There are several kinds of views:
- projection views, i.e. only one table involved just fields reduced
- join views, several tables, joins conditions stored in dictionary
- materialized views, here the joined data are actually stored in the database. Storing and synchronisation has to be done manually.
Only the last one creates real overhead. It should be the exception.
Join Views and Joins are nearly identical. The view is better for reuse. The join is better in complicated, becuase if the access goes wrong, it can often be fixed by adding a hint. Hints can not be added to views.
Abraham Bukit points out:
If it is cluster table, (you can't use join). If it is buffered table, I would also say avoid join.
If they all are transaction table which are not buffered and are not cluster tables.
He further supports Siegfried's statement that FAE is easier to undestand than INNER JOINs.
Thomas Zloch says, regarding buffered tables:
At least think twice, maybe compare runtimes if in doubt.
So, unless someone has some EVIDENCE that FOR ALL ENTRIES is better, I don't think we want to see this discussed further.
Kind regards
MattTo give food for thought here's an example I gave in a thread:
If you have a statement like
SELECT ... FOR ALL ENTRIES IN FAE_itab WHERE f = FAE_itab-f.
SAP sends it to the database depending how the parameter rsdb/prefer_union_all is set:
rsdb/prefer_union_all = 0 =>
SELECT ... WHERE f = FAE_itab[1]-f
OR f = FAE_itab[2]-f
OR f = FAE_itab[N]-f
You have some influence of the generated statement type: Instead of OR'ed fields an IN list can be used
if you have only a single coulmn N to compare:
rsdb/prefer_in_itab_opt parameter:
SELECT ... WHERE f IN (itab[1]-f, itab[2]-f, ..., itab[N]-f)
rsdb/prefer_union_all = 1 =>
SELECT ... WHERE f = FAE_itab[1]-f
UNION ALL SELECT ... WHERE f = FAE_itab[2]-f
UNION ALL SELECT ... WHERE f = FAE_itab[N]-f
see: Note 48230 - Parameters for the SELECT ... FOR ALL ENTRIES statement
As you can see for the 2nd parameter several statements are generated and combined with a UNION ALL,
the first setting generates statements with OR's (or uses IN if possible) for the entries in FAE_itab.
I give you a little example here (my parameters are set in a way that the OR's are translated to IN lists; i traced the execution in ST05)
Select myid into table t_tabcount from mydbtable
for all entries in t_table " 484 entries
where myid = t_table-myid .
ST05 trace:
|Transaction SEU_INT|Work process no 0|Proc.type DIA|Client 200|User |
|Duration |Obj. name |Op. |Recs.|RC |Statement|
| 640|mydbtable |PREPARE| | 0|SELECT WHERE "myid" IN ( :A0 , :A1 , :A2 , :A3 , :A4 ) AND "myid" = :A5|
| 2|mydbtable |OPEN | | 0|SELECT WHERE "myid" IN ( 1 , 2 , 3 , 4 , 5 ) AND "myid" = 72 |
| 2.536|mydbtable |FETCH | 0| 1403| |
| 3|mydbtable |REOPEN | | 0|SELECT WHERE "myid" IN ( 6 , 7 , 8 , 9 , 10 ) AND "myid" = 72 |
| 118|mydbtable |FETCH | 0| |
| 2|mydbtable |REOPEN | | 0|SELECT WHERE "myid" IN ( 11 , 12 , 13 , 14 , 15 ) AND "myid" = 72 |
| 3|mydbtable |REOPEN | | 0|SELECT WHERE "myid" IN ( 475 , 476 , 477 , 478 , 479 ) AND "myid" = 72 |
| 94|mydbtable |FETCH | 0| 1403| |
| 2|mydbtable |REOPEN | | 0|SELECT WHERE "myid" IN ( 480 , 481 , 482 , 483 , 484 ) AND "myid" = 72 |
You see the IN list contained 5 entries each , wich made up about 97 statements for all 484 entries.
For every statment you have a single fetch operation wich means a separate access to the database.
If you would replace the FAE with a join you would only have one fetch to the database.
With the example above we can derive these observations:
1. From database point of view these settings kill performance when you access a big table and/or have a lot of entries or columns in your FAE_itab. Furthermore, you hide information what data you will access
at all and thus you block the database from creating a more efficient execution plan because it DOESN'T KNOW wich data you will select in the next step. I.e. it may be more efficient to scan the table in one shot instead of having many index accesses - but the database can make this decision only if it can examine ONE statement that has ALL the information of what data to retrieve.
2. A second impact is that with every statement execution you trigger the allocation of database resources
wich will contribute to the overhead described above.
Said that, FAE can never be a replacement for joining big tables (think of having a table with thousands of records in a FAE table )
Edited by: kishan P on Nov 2, 2010 2:16 PM - Format Fixed -
Relationship between tables while using inner joins.
Hi,
I had a few clarifications on "inner joins", and as i was going through the forum, i came across two points,
1. In one of the threads it said " inner joins is applicable for tables that have a parent child relationship.
2. In another thread it said " inner join is established from master table (the table on the left) to the transcation table (the table on the right)".
I have two clarifications based on the above points.
1. Is it necessary that the tables on which im performing an inner join should have a parent-child/children relationship or is it enough that the tables just have a common field.
2. Also is it necessary that the master table should come first, (or can i use any child table from where i can fetch the records when there is a mater table in my report) as shown below.
Eg: select * <fields> from <master table> inner join <table> on <field> into <itab>.
Edited by: Narayananchandran on Dec 27, 2010 12:31 PMhave two clarifications based on the above points.
1. Is it necessary that the tables on which im performing an inner join should have a parent-child/children relationship or is it enough that the tables just have a common field.
2. Also is it necessary that the master table should come first, (or can i use any child table from where i can fetch the records when there is a mater table in my report) as shown below.
Eg: select * <fields> from <master table> inner join <table> on <field> into <itab>
1) NO
2) NO
Maybe you are looking for
-
What's wrong with this picture (unbundle display glitch)?
Let me state first that I actually like the look of what I am going to show you, and I am tempted to suggest it as an actual feature... In any case, here it is: This is an unbundle node in an actual diagram. All items are connected. I was simply hove
-
PROBLEms with videos imac G4 flat 17'
PROBLEms with videos in imac G4 flat 17'
-
Drag and Drop Mp3s stop working
I have 30 GB IPOD video. Till a couple of days, I was always able to drag and drop, folders containing mp3 files that I created in past from CDs etc and stored on my hard disc, directly on to my IPOD and it would add them to my IPOD music library. No
-
all help is appreciated
-
Hello, I recently synced the mail application with two email accounts I use (one was assigned for work and the other is for personal mail). I have tried deleting messages and keep getting this message for both accounts: The IMAP command "UID COPY" (t