LEFT OUTER JOIN with SubQuery
I have two tables and I want to return all data from the first table with a piece of information from the second based on an effective date being at least a certain value. The tables I am working with contain billions of rows so I need a solution that will also scale.
Sample tables:
create table pp ( x number, y number);
create table ec ( x number, y number, effdate date);
insert into pp values (1,2);
insert into pp values (2,3);
insert into pp values (1,3);
insert into ec values (1,2,sysdate);
insert into ec values (2,3,sysdate);
insert into ec values (1,3,sysdate+365);
commit;
select * from pp, ec where pp.x = ec.x(+) and pp.y=ec.y(+)
and (effdate = ( select max(effdate) from ec ecc where ecc.y=ec.y and ecc.x = ec.x and effdate < sysdate) or effdate is null);
The above query (and the one below) returns two rows. it does not return where the date does not meet the criteria.
select * from pp LEFT OUTER JOIN ec ON pp.x = ec.x and pp.y=ec.y
WHERE (effdate = ( select max(effdate) from ec ecc where ecc.y=ec.y and ecc.x = ec.x and effdate < sysdate) or effdate is null);
This returns the three rows BUT IS VERY SLOW when run against the billion+ row table (because we cannot correlate the subquery results.)
select * from pp LEFT OUTER JOIN (SELECT x, y, effdate
FROM ec WHERE effDate = (SELECT MAX(EFFdate) from ec ecc where ecc.y=ec.y and ecc.x = ec.x and effdate < sysdate)) c ON c.x = pp.x and c.y = pp.y;
It would help quite a bit to know
1) your Oracle version
2) your indexes and data volumes (do BOTH tables have billions of rows?)
But here's something that may perform faster.
ME_XE? WITH Maximizied AS
2 (
3 SELECT
4 MAX(EffDate),
5 x,
6 y
7 FROM ec
8 WHERE EffDate < SYSDATE
9 GROUP BY x, y
10 )
11 SELECT *
12 FROM pp p, Maximizied m
13 WHERE p.x = m.x (+)
14 AND p.y = m.y (+);
X Y MAX(EFFDAT X Y
2 3 05-29-2008 2 3
1 2 05-29-2008 1 2
1 3
3 rows selected.
Elapsed: 00:00:00.03
Similar Messages
-
Case statement resulting into Left outer join with other tables
Hi All ,
I am facing a stuation where a Case statement on one of the logical columns in Answers is resulting into a left outer join with a table in the query.
If we remove the case stmt, the table is not being acessed.
The case stmt is a simple one and no other logical column is being accessed in the case stmt.
Please advice .
Thanks.Hi Sai,
No ..we dont have any left outer join ...its just that I am selecting measure from F1 which has a confimred dimension D1 with F2.Now when I dont have case stmt on measure from F1(Case stmt is something like : CASE WHEN "- P table"."P Column" = 'Y' THEN 'Right' ELSE 'Wrong' END), then it doesnt query F2.
However as soon as I introduce the case stmt ,the query creates a left outer join with F2.
Thanks. -
Left Outer Join with more than two tables in both CR 8.5 and XIR2
I am trying to create a report and I have tried two versions of Crystal but I ultimately need the report in CR8.5 for compatibility with the client's system. I think I am starting to figure out what might be wrong and it might be my understanding of SQL, but I can't see why someone hasn't needed this in the past. Ultimately I want to see all projects and any journal entry that might be posted for that project.
Database is MySQL 5.0.38 and using MySQL ODBC driver 3.51.19.
Project header table information will be populated. Each line item on a journal entry can be tagged with the project ID. But for me to pull the journal entry date I need also to link to a third table for the journal entry header info.
I want to see all projects, whether a journal entry has been posted or not.
So the links are like this
ProjectHeader --->Left Outer Join ---> JELines ---> Inner Join ---> JEHeader
I think in this scenerio Crystal is treating the LOJ as an IJ.
I created two brand new reports today, one in CR8.5 and one in CR XIR2. Once I edited the automatic CR8.5 SQL statement (which I have been doing for years, usually without problem), they both ran properly. I linked customers to their invoices. Customers without invoices showed properly. But then I linked the invoices to the payments of the invoices and immediately lost customers without orders in both reports.
So apparently only two tables are allowed in Outer Joins. Does this make sense? I checked out the w3schools tutorial on SQL and it doesn't mention this limitation and I can't find anywhere else that it specifically indicates this but all samples of code I have seen only show two tables. I just thought for presentation as a sample that was easiest to understand and we could expand as necessary.
If this is correct, how does one go about accounting for this kind of thing? One solution that goes through my mind is creating a view at the database level for the link between journal entry lines and journal entry headers. Would this be a good solution under normal circumstances?
A second option that I had to implement because of timelines, is to use a subreport linked to the main report through the project ID to pull the information for the journal entries and just pass the totals I need to the main report through a shared variable.
These aren't normal circumstances because I don't have access to the database so I can't create the view. I have come across this concept several times and I have been able to use subreports to solve it but I am trying to find a better solution for the future as sometimes subreports can be slow. So are there any alternatives I have not considered here?
TIA rasincSo after some more work and another post. I was able to get this to work.
Items disappear when linking to another table
My issues were two fold. I was selecting on the tables on the right-side of the original Inner Join. However, I was checking for Nulls. This apparently is correct but you must check for the Nulls first eg. (IsNull (JEHeader.Field1) OR JEHeader.Field1 <= 100). I had my original statement reversed checking for <= 100 before checking for Nulls.
I also did not set all links to be Left Outer Join. I had the Inner Join. I actually have about 6 tables in this report so all the links need to be set Outer Join. So this now seems to be corrected.
Thanks -
OJ syntax for multi-table left outer join with MS Oracle Driver
I have a multi-table left outer join that works fine in SQL Server ODBC Driver, Oracle ODBC driver 8.01.07.00, but not with Microsoft ODBC Driver for Oracle 2.573.7326.0
SELECT * from { oj A LEFT OUTER JOIN B ON A.col1 = B.col1 LEFT OUTER JOIN C ON A.col1 = C.col1 }
I noticed someone had a similar problem (the proposed solution doesn't work):
http://www.justpbinfo.com/listarchive/msg02874.html
Does anyone know how to get this working with the Microsoft ODBC Driver for Oracle? Or does it just not work?The Microsoft ODBC Driver for Oracle 2.573.7326.0 does perform the same 'fix up' with {oj} in Oracle 8i. The problem is that it doesn't work when joining more than two tables:
This works:
SELECT * from { oj A LEFT OUTER JOIN B ON A.col1 = B.col1}
This doesn't work:
SELECT * from { oj A LEFT OUTER JOIN B ON A.col1 = B.col1 LEFT OUTER JOIN C ON B.col1 = C.col1 }
(The second query will work with the Oracle Oracle ODBC driver, with a bit of tweaking. But I haven't found a way to get it to work with the Microsoft ODBC Driver for Oracle 2.573.7326.0. My suspicion is that it just doesn't work.)
Gavin -
Left outer join with multiple conditions
Is it possible to add to a left outer join (= anyOfAllowingNone) more than the primary condition (in SQL this would be added per "and").
Background: The execution plan of the produced SQL shows large results on which the final filter is applied although I have conditions that would decrease this last result set much earlier...There is no easy way to do this in TopLink expressions, other than including the join in the regular where clause as you have done. Does it make a big impact in the performance of your query?
<p>
You could use custom SQL for the query.
<p>
Or you could potentially define a OneToOneQueryKey in your TopLink descriptor that includes the additional join criteria and call anyOfAllowingNone using this query key.
<p>
<p>---
<p>James Sutherland -
Left outer join with NVL as part of the join criteria
Hi,
I have query like this:
Select
Main.X_ID,
NVL(Option1.Y_ID, Option2.Y_ID),
Main.Z_ID
from TableMain Main
left join (Select X_ID, Y_ID from TableOption where type_cd = 'Type1') Option1
on Main.X_ID = Option1.X_ID
left join (Select X_ID, Y_ID from TableOption where type_cd = 'Type2') Option2
on Main.X_ID = Option2.X_ID
left join TableSub Sub
on Main.Z_ID = Sub.Z_ID
and Sub.Y_ID = NVL(Option1.Y_ID, Option2.Y_ID)
where Sub.Z_ID is null and Sub.Y_ID is null
Basically i want to show all in Z_IDs TableMain that are not in TableSub where the joining Y_ID is Type1 and if there is not a Y_ID for Type1, then use the Y_ID for Type2.
The query works if Type1 exists but doesnt if Type1 doesnt and Type2 does.
Is NVL the correct function to use in the join? Or is there a better way to write such a query?
Any help would be greatly appreciated. Thanks!!
FYI all IDs are NUMBERs.Hopefully this is easier to understand :)
Im using 11g.
DDL and data:
create table tablemain (
x_id number (20),
z_id number (20),
amount number(20)
insert into tablemain values (1, 1000, 6767.45);
insert into tablemain values (1, 1001, 767.45);
insert into tablemain values (1, 1002, 67.85);
insert into tablemain values (1, 1003, 997.85);
insert into tablemain values (2, 1002, 1997.85);
insert into tablemain values (2, 1004, 197.85);
insert into tablemain values (2, 1005, 7.85);
insert into tablemain values (3, 1000, 7.44);
insert into tablemain values (3, 1006, 447.88);
create table tableoption (
y_id number (20),
x_id number (20),
type_cd varchar2(20)
insert into tableoption values (800, 1, 'Type1');
insert into tableoption values (800, 3, 'Type2');
insert into tableoption values (801, 1, 'Type2');
insert into tableoption values (802, 2, 'Type1');
create table tablesub (
y_id number (20),
z_id number (20)
insert into tablesub values (800, 1000);
insert into tablesub values (800, 1001);
insert into tablesub values (800, 1004);
insert into tablesub values (800, 1006);
insert into tablesub values (801, 1001);
insert into tablesub values (801, 1002);
insert into tablesub values (801, 1005);
insert into tablesub values (801, 1006);
insert into tablesub values (802, 1005);
insert into tablesub values (802, 1004);Query:
SELECT Nvl(option1.y_id, option2.y_id) as y_id,
Nvl(option1.x_id, option2.x_id) as x_id,
mains.z_id,
mains.amount
FROM tablemain mains
left join (SELECT x_id,
y_id
FROM tableoption
WHERE type_cd = 'Type1') option1
ON mains.x_id = option1.x_id
left join (SELECT x_id,
y_id
FROM tableoption
WHERE type_cd = 'Type2') option2
ON mains.x_id = option2.x_id
left join tablesub sub
ON mains.z_id = sub.z_id
AND sub.y_id = Nvl(option1.y_id, option2.y_id)
WHERE sub.z_id IS NULL
AND sub.y_id IS NULL What the output should be:
y_id ---- x_id ---- z_id ---- amount
800 ---- 1 ---- 1002 ---- 67.85
800 ---- 1 ---- 1003 ---- 997.85
801 ---- 1 ---- 1000 ---- 6767.45
801 ---- 1 ---- 1003 ---- 997.85
802 ---- 2 ---- 1002 ---- 1997.85
Currently the output of the query is:
800 ---- 1 ---- 1002 ---- 67.85
800 ---- 1 ---- 1003 ---- 997.85
802 ---- 2 ---- 1002 ---- 1997.85
It is missing where 801 is type2 only in the tableoption:
801 ---- 1 ---- 1000 ---- 6767.45
801 ---- 1 ---- 1003 ---- 997.85
Edited by: Hazy on Feb 22, 2012 3:25 PM -
Restriction to Left Outer Joins in PS Query
Hello I am trying to do Left Outer JOin in PS QUERY. I need to do dept tbl, job code tbl and locatable as left outer joins with JOB Table. Looks like in PS QUERY there is a error message saying as below. Can someone has any workaround to achieve this in PS QUERY. I know I can create a View and use that in PS QUERY but BUsiness Users are dependent on IT, so that doesn't work. Also, adding JOB table multiple times works but I am looking for better solution if anyone had come accorss working through PS QUERY Outer JOins.
Windows Internet Explorer
Left outer joins must be joined to the last record in the query. (139,290)
OK
Thanks,
SC.Hi Mike,
According to your description, you want to improve the performance for your DAX query in SQL Server Analysis Service Tabular model, right? Here is a white paper describes strategies and specific techniques for getting the best performance from your tabular
models, including processing and partitioning strategies, DAX query tuning, and server tuning for specific workloads.
http://msdn.microsoft.com/en-us/library/dn393915.aspx
Since this is a complex DAX query, from a support perspective this is really beyond what we can do here in the forums. If you cannot determine your answer here or on your own, consider opening a support case with Microsoft. Visit this link to see the various
support options that are available to better meet your needs:
http://support.microsoft.com/default.aspx?id=fh;en-us;offerprophone
Regards,
Charlie Liao
TechNet Community Support -
Left outer join using multiple table
Hi,
I am trying to use left outer join with multiple tables , the join condition will be based on PERNR and BEGDA & ENDA for each infotype in selection screen.
select pa00~pernr pa00~begda pa00~endda pa00~massn pa00~massg pa00~stat2 pa00~aedtm pa00~uname
pa01~begda pa01~endda pa01~bukrs pa01~persg pa01~persk pa01~mstbr pa01~ename pa01~aedtm pa01~uname
pa02~begda pa02~endda pa02~nachn pa02~vorna pa02~midnm pa02~aedtm pa02~uname
pa016~begda pa016~endda pa016~cttyp pa016~aedtm pa016~uname
into CORRESPONDING FIELDS OF TABLE i_pall
from ( PA0000 as pa00 left OUTER JOIN pa0001 as pa01 on pa00~pernr = pa01~pernr )
left OUTER JOIN pa0002 as pa02 on pa00~pernr eq pa02~pernr )
left OUTER JOIN pa0016 as pa016 on pa00~pernr eq pa016~pernr )
where pa00~pernr in S_pernr
AND pa00~begda in s_bg0000
and pa00~endda in s_nd0000.
but this fails to fetch the value of begda enda from each pa0000,pa0001,pa0002,pa0016.
Please help!
MonirulWhy don't you use the standard logical database PNPCE and then Provide statement?
-
Hi,
I am trying to create a materialized view and trying replace + left outer join with 'left outer join' clause. I am getting
ERROR at line 68:
ORA-00904: "RF"."DATA_TYPE_ID": invalid identifier
Here is the sql I am using. Any help is appreciated.
CREATE MATERIALIZED VIEW HHC_CUSTOM.HHC_RESULT_FIELD_DIMENSION0925 (DATA_ELEMENT_ID,FIELD,PROFILE,PROFILE_ID,PARENT_FIELD,PARENT_PROFILE,PARENT_PROFILE_ID,DATA_TYPE,DECODE_TYPE,CFG_GROUP,CFG_SET,ACTIVITY_COUNT)
TABLESPACE CUSTOM_01
PCTUSED 0
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 80K
NEXT 1M
MINEXTENTS 1
MAXEXTENTS UNLIMITED
PCTINCREASE 0
BUFFER_POOL DEFAULT
FLASH_CACHE DEFAULT
CELL_FLASH_CACHE DEFAULT
NOCACHE
ENABLE ROW MOVEMENT
NOLOGGING
NOCOMPRESS
NOPARALLEL
BUILD IMMEDIATE
REFRESH COMPLETE on DEMand
WITH PRIMARY KEY
AS
/* Formatted on 9/25/2012 11:53:36 AM (QP5 v5.215.12089.38647) */
SELECT /*+ ALL_ROWS FULL(rf) FULL(dt) FULL(dc) FULL(rd) FULL(mc) FULL(ad) FULL(ag) USE_HASH(rf,dt,dc,rd,mc,ad,ag) INDEX(prf,KP_RESULT_FIELD) INDEX(prd,KP_RESULT_PROFILE) INDEX(pmc,KP_RESULT_MULTI_FIELD_PROFILE) INDEX(pad,KP_ASSESS_PROFILE) INDEX(pag,KP_ASSESS_MULTI_FIELD_PROFILE) USE_NL(prf,prd,pmc,pad,pag) ORDERED(rf,dt,dc,rd,mc,ad,ag,prf,prd,pmc,pad,pag) */
rf.data_element_id AS data_element_id,
rf.name AS field,
DECODE (SUBSTR (rf.data_element_id, 1, 3),
'RD/', rd.name,
'AG/', ag.name,
'AD/', ad.name,
'MC/', mc.name)
AS profile,
DECODE (SUBSTR (rf.data_element_id, 1, 3),
'RD/', rd.profile_id,
'AG/', ag.profile_id,
'AD/', ad.profile_id,
'MC/', mc.profile_id)
AS profile_id,
prf.name AS parent_field,
DECODE (SUBSTR (rf.parent_profile_field_id, 1, 3),
NULL, NULL,
'RD/', prd.name,
'AD/', pad.name,
'AG/', pag.NAME, --shouldn't happen
'MC/', pmc.name --shouldn't happen
AS parent_profile,
DECODE (SUBSTR (rf.parent_profile_field_id, 1, 3),
NULL, NULL,
'RD/', prd.profile_id,
'AD/', pad.profile_id,
'AG/', pag.profile_id, --shouldn't happen
'MC/', pmc.profile_id --shouldn't happen
AS parent_profile_id,
dt.name AS data_type,
NVL (dc.name,
DECODE (UPPER (dt.name), 'ORGANISM', 'Organism', 'Not Coded'))
AS decode_type,
NVL (cfg.cfg_group, 'UNDEFINED') AS cfg_group,
NVL (cfg.cfg_set, 'UNDEFINED') AS cfg_set,
DECODE (rslt.data_element_id, NULL, 0, rslt.activity_count)
AS activity_count
FROM ud_master.result_field rf,ud_master.result_field prf
join ud_master.data_type dt on (rf.data_type_id=dt.data_type_id)
left outer join ud_master.decode_type dc on (rf.decode_source_id = dc.decode_source_id)
left outer join ud_master.result_profile rd on (rf.profile_id = rd.profile_id)
left outer join ud_master.result_multi_field_profile mc on (rf.profile_id = mc.profile_id)
left outer join ud_master.assess_profile ad on (rf.profile_id = ad.profile_id)
left outer join ud_master.assess_multi_field_profile ag on (rf.profile_id = ag.profile_id)
left outer join ud_master.result_field rf on (prf.parent_profile_field_id = rf.data_element_id)
left outer join ud_master.result_profile prd on (prf.profile_id = prd.profile_id)
left outer join ud_master.result_multi_field_profile pmc on (prf.profile_id = pmc.profile_id)
left outer join ud_master.assess_profile pad on (prf.profile_id = pad.profile_id)
left outer join ud_master.assess_multi_field_profile pag on (rf.profile_id = pag.profile_id)
left outer join (SELECT * FROM hhc_custom.dw_cfg_v WHERE cfg_type_id = 1) cfg on (rf.data_element_id = cfg.cfg_value)
left outer join (SELECT data_element_id, COUNT (*) AS activity_count FROM ud_master.result GROUP BY data_element_id) rslt on (rf.data_element_id = rslt.data_element_id);
Regards,
KoteshHi Monica,
I need to have 2 aliases for ud_master.result_field table
So I f I change it like this
CREATE MATERIALIZED VIEW HHC_CUSTOM.HHC_RESULT_FIELD_DIMENSION0925 (DATA_ELEMENT_ID,FIELD,PROFILE,PROFILE_ID,PARENT_FIELD,PARENT_PROFILE,PARENT_PROFILE_ID,DATA_TYPE,DECODE_TYPE,CFG_GROUP,CFG_SET,ACTIVITY_COUNT)
TABLESPACE CUSTOM_01
PCTUSED 0
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 80K
NEXT 1M
MINEXTENTS 1
MAXEXTENTS UNLIMITED
PCTINCREASE 0
BUFFER_POOL DEFAULT
FLASH_CACHE DEFAULT
CELL_FLASH_CACHE DEFAULT
NOCACHE
ENABLE ROW MOVEMENT
NOLOGGING
NOCOMPRESS
NOPARALLEL
BUILD IMMEDIATE
REFRESH COMPLETE on DEMand
WITH PRIMARY KEY
AS
/* Formatted on 9/25/2012 11:53:36 AM (QP5 v5.215.12089.38647) */
SELECT /*+ ALL_ROWS FULL(rf) FULL(dt) FULL(dc) FULL(rd) FULL(mc) FULL(ad) FULL(ag) USE_HASH(rf,dt,dc,rd,mc,ad,ag) INDEX(prf,KP_RESULT_FIELD) INDEX(prd,KP_RESULT_PROFILE) INDEX(pmc,KP_RESULT_MULTI_FIELD_PROFILE) INDEX(pad,KP_ASSESS_PROFILE) INDEX(pag,KP_ASSESS_MULTI_FIELD_PROFILE) USE_NL(prf,prd,pmc,pad,pag) ORDERED(rf,dt,dc,rd,mc,ad,ag,prf,prd,pmc,pad,pag) */
rf.data_element_id AS data_element_id,
rf.name AS field,
DECODE (SUBSTR (rf.data_element_id, 1, 3),
'RD/', rd.name,
'AG/', ag.name,
'AD/', ad.name,
'MC/', mc.name)
AS profile,
DECODE (SUBSTR (rf.data_element_id, 1, 3),
'RD/', rd.profile_id,
'AG/', ag.profile_id,
'AD/', ad.profile_id,
'MC/', mc.profile_id)
AS profile_id,
prf.name AS parent_field,
DECODE (SUBSTR (rf.parent_profile_field_id, 1, 3),
NULL, NULL,
'RD/', prd.name,
'AD/', pad.name,
'AG/', pag.NAME, --shouldn't happen
'MC/', pmc.name --shouldn't happen
AS parent_profile,
DECODE (SUBSTR (rf.parent_profile_field_id, 1, 3),
NULL, NULL,
'RD/', prd.profile_id,
'AD/', pad.profile_id,
'AG/', pag.profile_id, --shouldn't happen
'MC/', pmc.profile_id --shouldn't happen
AS parent_profile_id,
dt.name AS data_type,
NVL (dc.name,
DECODE (UPPER (dt.name), 'ORGANISM', 'Organism', 'Not Coded'))
AS decode_type,
NVL (cfg.cfg_group, 'UNDEFINED') AS cfg_group,
NVL (cfg.cfg_set, 'UNDEFINED') AS cfg_set,
DECODE (rslt.data_element_id, NULL, 0, rslt.activity_count)
AS activity_count
FROM ud_master.result_field rf,ud_master.result_field prf
join ud_master.data_type dt on (prf.data_type_id=dt.data_type_id)
left outer join ud_master.decode_type dc on (prf.decode_source_id = dc.decode_source_id)
left outer join ud_master.result_profile rd on (prf.profile_id = rd.profile_id)
left outer join ud_master.result_multi_field_profile mc on (prf.profile_id = mc.profile_id)
left outer join ud_master.assess_profile ad on (prf.profile_id = ad.profile_id)
left outer join ud_master.assess_multi_field_profile ag on (prf.profile_id = ag.profile_id)
left outer join ud_master.result_field rf on (prf.parent_profile_field_id = rf.data_element_id)
left outer join ud_master.result_profile prd on (prf.profile_id = prd.profile_id)
left outer join ud_master.result_multi_field_profile pmc on (prf.profile_id = pmc.profile_id)
left outer join ud_master.assess_profile pad on (prf.profile_id = pad.profile_id)
left outer join ud_master.assess_multi_field_profile pag on (rf.profile_id = pag.profile_id)
left outer join (SELECT * FROM hhc_custom.dw_cfg_v WHERE cfg_type_id = 1) cfg on (rf.data_element_id = cfg.cfg_value)
left outer join (SELECT data_element_id, COUNT (*) AS activity_count FROM ud_master.result GROUP BY data_element_id) rslt on (rf.data_element_id = rslt.data_element_id);
I am getting the following error
DECODE (SUBSTR (rf.parent_profile_field_id, 1, 3),
ERROR at line 51:
ORA-00918: column ambiguously defined
Following is the original query I tried to modify
CREATE MATERIALIZED VIEW HHC_CUSTOM.HHC_RESULT_FIELD_DIMENSION (DATA_ELEMENT_ID,FIELD,PROFILE,PROFILE_ID,PARENT_FIELD,PARENT_PROFILE,PARENT_PROFILE_ID,DATA_TYPE,DECODE_TYPE,CFG_GROUP,CFG_SET,ACTIVITY_COUNT)
TABLESPACE CUSTOM_01
PCTUSED 0
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 80K
NEXT 1M
MINEXTENTS 1
MAXEXTENTS UNLIMITED
PCTINCREASE 0
BUFFER_POOL DEFAULT
FLASH_CACHE DEFAULT
CELL_FLASH_CACHE DEFAULT
NOCACHE
ENABLE ROW MOVEMENT
NOLOGGING
NOCOMPRESS
NOPARALLEL
BUILD IMMEDIATE
REFRESH COMPLETE ON DEMAND
WITH PRIMARY KEY
AS
/* Formatted on 9/26/2012 1:59:27 PM (QP5 v5.215.12089.38647) */
SELECT /*+ ALL_ROWS FULL(rf) FULL(dt) FULL(dc) FULL(rd) FULL(mc) FULL(ad) FULL(ag) USE_HASH(rf,dt,dc,rd,mc,ad,ag) INDEX(prf,KP_RESULT_FIELD) INDEX(prd,KP_RESULT_PROFILE) INDEX(pmc,KP_RESULT_MULTI_FIELD_PROFILE) INDEX(pad,KP_ASSESS_PROFILE) INDEX(pag,KP_ASSESS_MULTI_FIELD_PROFILE) USE_NL(prf,prd,pmc,pad,pag) ORDERED(rf,dt,dc,rd,mc,ad,ag,prf,prd,pmc,pad,pag) */
rf.data_element_id AS data_element_id,
rf.name AS field,
DECODE (SUBSTR (rf.data_element_id, 1, 3),
'RD/', rd.name,
'AG/', ag.name,
'AD/', ad.name,
'MC/', mc.name)
AS profile,
DECODE (SUBSTR (rf.data_element_id, 1, 3),
'RD/', rd.profile_id,
'AG/', ag.profile_id,
'AD/', ad.profile_id,
'MC/', mc.profile_id)
AS profile_id,
prf.name AS parent_field,
DECODE (SUBSTR (rf.parent_profile_field_id, 1, 3),
NULL, NULL,
'RD/', prd.name,
'AD/', pad.name,
'AG/', pag.NAME, --shouldn't happen
'MC/', pmc.name --shouldn't happen
AS parent_profile,
DECODE (SUBSTR (rf.parent_profile_field_id, 1, 3),
NULL, NULL,
'RD/', prd.profile_id,
'AD/', pad.profile_id,
'AG/', pag.profile_id, --shouldn't happen
'MC/', pmc.profile_id --shouldn't happen
AS parent_profile_id,
dt.name AS data_type,
NVL (dc.name,
DECODE (UPPER (dt.name), 'ORGANISM', 'Organism', 'Not Coded'))
AS decode_type,
NVL (cfg.cfg_group, 'UNDEFINED') AS cfg_group,
NVL (cfg.cfg_set, 'UNDEFINED') AS cfg_set,
DECODE (rslt.data_element_id, NULL, 0, rslt.activity_count)
AS activity_count
FROM ud_master.result_field rf,
ud_master.data_type dt,
ud_master.decode_type dc,
ud_master.result_profile rd,
ud_master.result_multi_field_profile mc,
ud_master.assess_profile ad,
ud_master.assess_multi_field_profile ag,
ud_master.result_field prf,
ud_master.result_profile prd,
ud_master.result_multi_field_profile pmc,
ud_master.assess_profile pad,
ud_master.assess_multi_field_profile pag,
(SELECT *
FROM hhc_custom.dw_cfg_v
WHERE cfg_type_id = 1) cfg,
( SELECT data_element_id, COUNT (*) AS activity_count
FROM ud_master.result
GROUP BY data_element_id) rslt
WHERE rf.data_type_id = dt.data_type_id
AND rf.decode_source_id = dc.decode_source_id(+)
AND rf.profile_id = rd.profile_id(+)
AND rf.profile_id = mc.profile_id(+)
AND rf.profile_id = ad.profile_id(+)
AND rf.profile_id = ag.profile_id(+)
AND rf.parent_profile_field_id = prf.data_element_id(+)
AND prf.profile_id = prd.profile_id(+)
AND prf.profile_id = pmc.profile_id(+)
AND prf.profile_id = pad.profile_id(+)
AND prf.profile_id = pag.profile_id(+)
AND rf.data_element_id = cfg.cfg_value(+)
AND rf.data_element_id = rslt.data_element_id(+);
Can you tell me how can I rewrite it with 'LEFT OUTER JOIN' syntax?
Regards,
Kotesh -
Problem with XMLTABLE and LEFT OUTER JOIN
Hi all.
I have one problem with XMLTABLE and LEFT OUTER JOIN, in 11g it returns correct result but in 10g it doesn't, it is trated as INNER JOIN.
SELECT * FROM v$version;
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
PL/SQL Release 11.2.0.1.0 - Production
"CORE 11.2.0.1.0 Production"
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
--test for 11g
CREATE TABLE XML_TEST(
ID NUMBER(2,0),
XML XMLTYPE
INSERT INTO XML_TEST
VALUES
1,
XMLTYPE
<msg>
<data>
<fields>
<id>g1</id>
<dat>data1</dat>
</fields>
</data>
</msg>
INSERT INTO XML_TEST
VALUES
2,
XMLTYPE
<msg>
<data>
<fields>
<id>g2</id>
<dat>data2</dat>
</fields>
</data>
</msg>
INSERT INTO XML_TEST
VALUES
3,
XMLTYPE
<msg>
<data>
<fields>
<id>g3</id>
<dat>data3</dat>
</fields>
<fields>
<id>g4</id>
<dat>data4</dat>
</fields>
<fields>
<dat>data5</dat>
</fields>
</data>
</msg>
SELECT
t.id,
x.dat,
y.seqno,
y.id_real
FROM
xml_test t,
XMLTABLE
'/msg/data/fields'
passing t.xml
columns
dat VARCHAR2(10) path 'dat',
id XMLTYPE path 'id'
)x LEFT OUTER JOIN
XMLTABLE
'id'
passing x.id
columns
seqno FOR ORDINALITY,
id_real VARCHAR2(30) PATH '.'
)y ON 1=1
ID DAT SEQNO ID_REAL
1 data1 1 g1
2 data2 1 g2
3 data3 1 g3
3 data4 1 g4
3 data5 Here's everything fine, now the problem:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bi
PL/SQL Release 10.2.0.1.0 - Production
"CORE 10.2.0.1.0 Production"
TNS for HPUX: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
--exactly the same environment as 11g (tables and rows)
SELECT
t.id,
x.dat,
y.seqno,
y.id_real
FROM
xml_test t,
XMLTABLE
'/msg/data/fields'
passing t.xml
columns
dat VARCHAR2(10) path 'dat',
id XMLTYPE path 'id'
)x LEFT OUTER JOIN
XMLTABLE
'id'
passing x.id
columns
seqno FOR ORDINALITY,
id_real VARCHAR2(30) PATH '.'
)y ON 1=1
ID DAT SEQNO ID_REAL
1 data1 1 g1
2 data2 1 g2
3 data3 1 g3
3 data4 1 g4As you can see in 10g I don't have the last row, it seems that Oracle 10g doesn't recognize the LEFT OUTER JOIN.
Is this a bug?, Metalink says that sometimes we can have an ORA-0600 but in this case there is no error returned, just incorrect results.
Please help.
Regards.Hi A_Non.
Thanks a lot, I tried with this:
SELECT
t.id,
x.dat,
y.seqno,
y.id_real
FROM
xml_test t,
XMLTABLE
'/msg/data/fields'
passing t.xml
columns
dat VARCHAR2(10) path 'dat',
id XMLTYPE path 'id'
)x,
XMLTABLE
'id'
passing x.id
columns
seqno FOR ORDINALITY,
id_real VARCHAR2(30) PATH '.'
)(+) y ;And is giving me the complete output.
Thanks again.
Regards. -
Left outer join 3 tables with where-statement
Hi folks,
I hope you can understand (and maybe solve) my problem.
Generally I try to left outer join three tables. The third table is used for a WHERE-statement.
The three table structures are the following:
table 1 (user)
user1 | key
table 2 (detail)
key | ID
table 3 (header)
ID | user2
...and I want to achieve the following structure (as example filled with data):
user | key | ID
|-----|----
xy | a | 001
xy | b | #
z | b | #
The clue ist the usage of the third table. I need the table to set user1 and user2 equal (WHERE) but there are two problems:
1) Obviously I can't left outer join two tables with each other. In this case I already used the 'key' of table 1 to join it with the 'key' of table 2. So I can't left outer join the 'ID' of table 2 with the 'ID' of table 3. Error message that I can only left outer join a table once. Any proposals?
2) I have to include a WHERE to equal user1 with user2. But I am not allowed to use the user2 from table 3 because of the left outer join.
I tried this coding:
SELECT auser1 akey b~id INTO TABLE itab FROM ( table1 AS a
LEFT OUTER JOIN table2 AS b ON akey = bkey )
LEFT OUTER JOIN table3 AS c ON bID = cID )
WHERE auser1 = cuser2.
I would really appreciate your help.
Regards
MrclSpdlIF you want to join a DB table with an internal table, you need to use the 'FOR ALL ENTRIES' statement.
select dbfields
into table itab2
from dbtab
for all entries in itab
where dbfield1 = itab-field1.
This will get you a second internal table with all the corresponding data for the first selection. You can then join them with a loop through the first table and a read table on the second table (for 1 - 1 relation) or a nested loop statement on both tables (for 1 - N relation). Make itab a hashed table when using read table with key, use a sorted table if you need to loop without key access.
Regards,
Freek -
Left Outer Joining multiple tables to one source table FAILS with VLD-1511
Hi all,
Is it me, or is OWB unable to handle left outer joining 1 source table to multiple other tables?
I want to load a fact table so I have 1 source table with measures. This table must be outer joined to some dimensions that have their FK in the fact table.
The SQL statement would look like this (and is perfectly valid):
select ...
from input, dim1, dim2
where input.c1 = dim1.c1(+)
and input.c2 = dim2.c2(+);
I put the where clause in the joiner operator and validate, but that gives me message VLD-1511: A table may be outer joined to at most one other table.
Even splitting this up into one outer join per joiner still gives this message.
A search and look around on the forum and on metalink shows there are related issues (like bug 3334035). Seemingly creating a view is the work-around to use.....? (ie downgrading owb to a simple gui tool) }-;
Have other people experienced this problem of not being able to outer join one input table to multiple other tables?
Thanks,
EdI have had some feedback from Oracle. It turns out this has to do with 2 issues. Below I have pasted the text that Support gave me:
<---------- START QUOTE ---------->
RESEARCH
=========
Bug 3437036 KEY LOOKUP DOES NOT DETECT ORA-1417 IN VALIDATE/GENERATE STEP
Unpublished Bug 4211684 FORWARD PORT OF BUG 3437036
shows:
Some more development has been completed when this bug is fixed in Paris.
The following are the details:
1. If the join condition contains a full outer join such as
tab1.c (+) = tab2.c (+) and tab2.c (+) = tab3.c
then the new validations implemented for this bug do not apply since
in OWB, full outer join triggers generation of joins in ANSI syntax.
ANSI syntax does not have the original problem the base bug of this
bug reported.
2. If the join condition does not contain any full outer join condition,
then the join is generated in Oracle join syntax, which is subject two
several restrictions. The fix to this bug check two of the restrictions.
3. The first restriction in Oracle syntax is that the outer join operator
"(+)" can only directly be attached to a column name. If you attach it
to an expression, such as the following:
(tab1.c + 1) (+) = tab2.c
Then there will be an ORA-936 error at the time of mapping deployment.
For this case, I have added a validation message VLD-1512 to error out
this situation.
4. The second restriction in Oracle syntax is that a table can only be
outer joined to exactly one other table.
For example, this is an invalid join in Oracle syntax:
tab1.c (+) = tab2.c and tab1.d (+) = tab3.d
because tab1 is left outer joined to tab2 and tab3.
But note that the following is still valid in Oracle syntax:
tab1.c (+) = tab2.c and tab1.d = tab3.d (+)
because tab1 is left outer joined to tab2 and right outer joined to tab3.
So this latter case does not violate the restriction that "same oj" to
more than 1 table is not allowed.
If same oj to more than 1 table is specified in a join condition,
VLD-1511 will be issued, and the map is made invalid.
<---------- END QUOTE ---------->
OWB does a partial validation, ie not all access paths are (can be) checked. A full check is only done by the database itself. So some scenarios (like checking whether multiple tables are outer joined the correct way) are not checked, and in this case are flagged with an error (even though it is actually a correct scenario).
Seemingly this was not flagged with an error in earlier versions of OWB, so beware, OWB behaviour may change when upgrading...
Alternative solutions are (1) using key lookups, (2) using a view with all outer joins in there, (3) using intermediate result tables between the joins.
Hope this info helps some people prevent spending too much time on a false error message,
Ed -
Can we join 3 tables with left outer join
hi friends.
Can any one tell how to join 3 tables using <b>left outer join</b>...i tried by taking some fields of <b>ekko,ekpo,eket</b>, but this not working ... plz give a sample code with some fields.Hi Uday
<b>Inner joins using 3 tables </b>
<i><b>Try this :-</b></i>
SELECT stpo~stlnr stpo~idnrk mast~matnr mara~mtart stpo~menge
INTO CORRESPONDING FIELDS OF TABLE zmat1 FROM mast
JOIN stpo ON stpo~stlnr = mast~stlnr
JOIN mara ON mara~matnr = mast~matnr
WHERE stpo~stlty = 'M' "AND stpo~idnrk IN s_matnr
AND mast~werks = 1000.
<b><i>Here s_matnr is a select-options on the selection-screen. </i></b>
<i><b>Or this. </b></i>
<b>Code: </b>
Select single Vbrk~Bukrs Vbrk~Kunrg Vbrk~Vbeln
Vbrk~Fkdat Vbrk~Bstnk_Vf Vbrk~Zterm
Tvzbt~Vtext
Vbak~Vbeln Vbak~Bstdk
Likp~Vbeln Likp~lfdat Likp~Lfuhr
into w_vbrk
from vbrk
inner join Tvzbt on Tvzbt~Zterm = Vbrk~Zterm and
Tvzbt~Spras = sy-langu
Inner join Vbfa as SalesLnk
on SalesLnk~vbeln = pu_vbeln and
SalesLnk~vbtyp_v = c_order
inner join Vbak on Vbak~Vbeln = SalesLnk~Vbelv
Inner join Vbfa as DeliveryLnk
on DeliveryLnk~vbeln = pu_vbeln and
DeliveryLnk~vbtyp_v = c_Delivery
inner join Likp on Likp~Vbeln = DeliveryLnk~Vbelv
where vbrk~vbeln = pu_Vbeln.
<i><b>This code locates sales, delivery and payment terms info from a billing document number.</b></i>
<i><b>or</b></i>
<b>
Here, this one also works fine :</b>
select zfpcd~cadivi zfpcd~proforma zfpcd~factura zfpcd~aniofactura
zfpcd~montousd zfpcd~montoap zfpcd~ebeln zfpcd~inco1
zfpcd~lifnr lfa1~name1 zcdvs~status zfpcd~conint
into it_lista
from zfpcd inner join zcdvs
on zfpcd~ebeln = zcdvs~ebeln
and zfpcd~proforma = zcdvs~proforma
and zfpcd~lifnr = zcdvs~lifnr
inner join lfa1
on zfpcd~lifnr = lfa1~lifnr
where zcdvs~status = '04'.
Reward if helpfull
Regards
Pavan -
I'm kind of new to using left outer joins, so I don't know if I'm doing it quite right. Right now there's only one table that may or may not have a corresponding record, so I'm only using left outer join on it. I get the error ORA-00904: "A"."SGBSTDN_PIDM": invalid identifier right now when I try to run my query. This gives me the impression that I need to use left outer join on all the tables in my FROM clause. Any suggestions on what I need to do?
/*Get those students not awarded ACG1 yet with an entry in shrlgpa*/
SELECT spriden_id id, spriden_last_name||', '||spriden_first_name name, sgbstdn_styp_code student_type,
sorhsch_graduation_date hsch_grad_date,shrlgpa_hours_earned hours_earned,rorenrl_finaid_adj_hr hours_enrolled,
0 AS disbursement_to_date, 0 AS offer_amt, 0 AS current_disbursement,
rnvand0_unmet_need unmet_need, 'N' AS awarded
FROM RCRESAR,RCRAPP1,SORHSCH,RORHSDT,SGBSTDN A,SORLCUR, shrlgpa, rorstat, ROBINST, spriden
,rnvand0
LEFT OUTER JOIN rorenrl ON (A.sgbstdn_pidm = rorenrl_pidm)
WHERE (RCRESAR_PELL_ELGBL = 'Y')
AND SORHSCH_GRADUATION_DATE>'01-JAN-2006'
AND RCRAPP1_CITZ_IND IN ('1','2')
AND RCRAPP1_CURR_REC_IND='Y'
/*Possible change once rigorous curr. decided AND (RORHSDT_AP_IB_COURSES = 'Y' OR RORHSDT_REQ_COURSES='Y')*/
AND RORHSDT_REQ_COURSES='Y'
AND sgbstdn_stst_code = 'AS'
AND SGBSTDN_STYP_CODE IN ('F','H','T')
AND (SORLCUR_DEGC_CODE LIKE 'B%' OR SORLCUR_DEGC_CODE LIKE 'A%'
OR SORLCUR_DEGC_CODE = 'UND')
AND sorlcur_seqno = (SELECT MAX(sorlcur_seqno)
FROM sorlcur
WHERE sorlcur_pidm = A.sgbstdn_pidm
AND sorlcur_term_code = &enrollment_term)
AND SORLCUR_CACT_CODE='ACTIVE'
AND rorenrl_term_code = &enrollment_term
AND shrlgpa_hours_earned BETWEEN 0 AND 29
AND shrlgpa_gpa_type_ind = 'O'
AND rorstat_pckg_comp_date IS NOT NULL
AND A.SGBSTDN_TERM_CODE_EFF = (SELECT MAX(B.SGBSTDN_TERM_CODE_EFF)
FROM SGBSTDN B
WHERE B.SGBSTDN_PIDM = A.SGBSTDN_PIDM
AND sgbstdn_term_code_eff <= &enrollment_term
AND NOT EXISTS (SELECT 'X'
FROM RPRAWRD
WHERE RCRESAR_PIDM = RPRAWRD_PIDM
AND RCRESAR_AIDY_CODE = RPRAWRD_AIDY_CODE
AND RPRAWRD_FUND_CODE = 'ACG1')
AND rorstat_pidm = rcresar_pidm
AND spriden_pidm = rcresar_pidm
AND RCRAPP1_PIDM = RCRESAR_PIDM
AND shrlgpa_pidm = rcresar_pidm
AND SORHSCH_PIDM = RCRESAR_PIDM
AND RORHSDT_PIDM = RCRESAR_PIDM
AND SGBSTDN_PIDM = RCRESAR_PIDM
AND SORLCUR_PIDM = RCRESAR_PIDM
AND rnvand0_pidm = rorstat_pidm
AND RCRESAR_INFC_CODE = RCRAPP1_INFC_CODE
AND RCRESAR_SEQ_NO = RCRAPP1_SEQ_NO
AND RCRAPP1_AIDY_CODE = RCRESAR_AIDY_CODE
AND ROBINST_AIDY_CODE = RCRESAR_AIDY_CODE
AND RCRESAR_AIDY_CODE = '&AIDY_CODE'
AND rorstat_aidy_code = rcresar_aidy_code
AND rnvand0_aidy_code = rcresar_aidy_code
AND spriden_change_ind IS NULL
ORDER BY nameFrank Kulash wrote:
Hi
blackhole82 wrote:
Yeah I realized that I was probably mixing styles after it wouldn't work. What you suggested does execute, so I assume it's right even though I'm not getting any rows at the moment. Don't assume it's correct: verify it
I suggest re-writing the query using all ANSI syntax.
Start with just two tables. Make sure that join is working.
When you have something that works perfectly with just those tables, then add one more table.
So if I wanted to left outer join onto shrlgpa too I would just need to add that underneath the join for rorenrl before the , and SORLCUR?In your existing query, it looks like shrlgpa is only connected to rcresar, using an inner join. Do you want to change that?At any rate, the order of tables using the old doesn't matter. Using ANSI notation, however, a join condition can only reference tables that have already been named in the same group of ANSI-joined tables.
So you would probably would have to re-arrange the FROM clause.
Sorry, I don't understand exactly what you want to do, so I can't tell you exactly how to do it.
Make you best guess, and try it.
If it doesn't produce the results you want, and you can't figure out how to fix it, then post the query, some sample data, and the desired results. If you post just the revised query, and a description of the problem, I'll try to answer, but without the sample data and desired results I can't guarantee that I can.Well I'm getting rows and the data seems to go with the query I had before using the outer join except for the records that have no record on shrlgpa. It appears that by having the clauses
AND shrlgpa_hours_earned BETWEEN 0 AND 29
AND shrlgpa_gpa_type_ind = 'O'that those I'm trying to pull in with the left outer join are being eliminated. Is it possible to still limit the hours earned while pulling in those who do not have a record on shrlgpa? Before I was just using a UNION to accomplish this, but I thought that I might be able to fine tune the query to eliminate the need for another UNION. -
Crystal Report with 2 oracle datasources (left outer join) very slow
I've made a crystal report with 2 oracle datasources (2 commands). I'm using crystal 10.
These 2 data sources are linked with a left outer join.
The report takes a while to run (more then one hour).
i can run Both query's in a couple of seconds/minutes, but it looks like crystal is runniing the second query for each record in the first query.
When i make the same report in BO. Just 2 queries with merged dimensions in the report, it is taking a couple of minutes to complete the report.
Question is if somebody knows how crystal is handling these 2 different data sources.
Is there any way to say to crystal to fetch the data of both queries and do the join after that?
At the moment it looks like that crystal is going to the other datasource for each record in the first query, which will cost a lot of time.Joris,
I've always had a bad time combining a Command with any other object. Performance seems to drop dramatically, just as you've described.
I can't tell you specifically why, it falls off so bad...
The solution I've used is to do a linked server query (at least that's what it's called in MS SQL Server) I've never used Oracle, but I'd be VERY surprised if it didn't have that same feature. This will keep 100% of the processing on the server(s) and will get your run times back to what you would expect.
HTH,
Jason
Maybe you are looking for
-
Interactive widget goes full screen but Review widget does not...
Anyone know why this is or if there is any way to make it go full screen? Thanks
-
MOVED: Problem with SATA DVD/RW
This topic has been moved to AMD64 nVidia Based board. Problem with SATA DVD/RW
-
Hi Experts, I need to submit the data in the adobe interactive form to the R/3 using abap webdynpro. But I don't know how to complete the submit code in the R/3 or the adobe form? Action: 1. create a adobe interactive form (a_interactive_form)in the
-
Multi Node configuration on Apps 11i
Hello, I need to add a second apps node and the Metalink Note 217368.1 is not very useful. I'd like a real case to try. Thanks
-
Implementation pbms and support tickets..
Hi, can anybody explain realtime implementation pbms and support issues...can u give me some ten examples...thanks to all