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.
Similar Messages
-
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?
-
Maximum number of tables that can be outer joined with one table in a query
Hi All,
Iam new to sql, so can you please let me know What is the maximum number of tables that can be outer joined with one table in a query?
Thanks,
Srinisrinu2 wrote:
Iam new to sql, so can you please let me know What is the maximum number of tables that can be outer joined with one table in a query?
There is no limit to the number of tables you can outer join as long as you join them correctly.
SQL> with a as
2 (
3 select 1 id, 2 b_key, 3 c_key from dual union all
4 select 2 id, 1 b_key, 4 c_key from dual union all
5 select 3 id, 3 b_key, 1 c_key from dual union all
6 select 4 id, 4 b_key, 2 c_key from dual
7 ),
8 b as
9 (
10 select 1 id, 1 c_key2 from dual union all
11 select 2 id, 5 c_key2 from dual union all
12 select 3 id, 3 c_key2 from dual union all
13 select 4 id, 2 c_key2 from dual
14 ),
15 c as
16 (
17 select 1 key1, 1 key2, '1-1' dta from dual union all
18 select 1 key1, 2 key2, '1-2' dta from dual union all
19 select 1 key1, 3 key2, '1-3' dta from dual union all
20 select 1 key1, 4 key2, '1-4' dta from dual union all
21 select 2 key1, 1 key2, '2-1' dta from dual union all
22 select 2 key1, 2 key2, '2-2' dta from dual union all
23 select 2 key1, 3 key2, '2-3' dta from dual union all
24 select 2 key1, 4 key2, '2-4' dta from dual union all
25 select 3 key1, 1 key2, '3-1' dta from dual union all
26 select 3 key1, 2 key2, '3-2' dta from dual union all
27 select 3 key1, 3 key2, '3-3' dta from dual union all
28 select 3 key1, 4 key2, '3-4' dta from dual union all
29 select 4 key1, 1 key2, '4-1' dta from dual union all
30 select 4 key1, 2 key2, '4-2' dta from dual union all
31 select 4 key1, 3 key2, '4-3' dta from dual union all
32 select 4 key1, 4 key2, '4-4' dta from dual
33 )
34 select d.a_id, d.b_id, c.key1 as c_key1, c.key2 as c_key3, c.dta
35 from
36 c,
37 (
38 select
39 a.id as a_id, b.id as b_id, a.c_key, b.c_key2
40 from a, b
41 where a.b_key = b.id
42 ) d
43 where d.c_key = c.key1 (+)
44 and d.c_key2 = c.key2 (+);
A_ID B_ID C_KEY1 C_KEY3 DTA
3 3 1 3 1-3
4 4 2 2 2-2
2 1 4 1 4-1
1 2
SQL> -
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 -
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 ouer join with internal table
Good morning to everybody
I need created a internal table with 2 internal table but 1 is primary.
I tried use "left outer join" but it allows only with table and not with internal tabel
I would to be this result
a a xxx
b
c c zzz
d d sss
e
f f ttt
How can i do it?
Thanks a lot for your support
Beste regatrdsHi,
The following code is for your reference:
data: begin of wa1,
key type c,
end of wa1.
data: begin of wa2,
key type c,
var(3) type c,
end of wa2.
data: begin of wa3,
key1 type c,
key2 type c,
var(3) type c,
end of wa3.
data: itab1 like standard table of wa1,
itab2 like standard table of wa2,
itab3 like standard table of wa3.
wa1-key = 'a'.
append wa1 to itab1.
wa1-key = 'b'.
append wa1 to itab1.
wa1-key = 'c'.
append wa1 to itab1.
wa1-key = 'd'.
append wa1 to itab1.
wa1-key = 'e'.
append wa1 to itab1.
wa1-key = 'f'.
append wa1 to itab1.
clear wa1.
wa2-key = 'a'.
wa2-var = 'zzz'.
append wa2 to itab2.
wa2-key = 'c'.
wa2-var = 'yyy'.
append wa2 to itab2.
wa2-key = 'd'.
wa2-var = 'ttt'.
append wa2 to itab2.
wa2-key = 'f'.
wa2-var = 'sss'.
append wa2 to itab2.
clear wa2.
loop at itab1 into wa1.
read table itab2 into wa2
with key key = wa1-key
binary search.
if sy-subrc = 0.
wa3-key1 = wa1-key.
wa3-key2 = wa2-key.
wa3-var = wa2-var.
append wa3 to itab3.
clear wa3.
else.
append wa1 to itab3.
endif.
endloop.
loop at itab3 into wa3.
write:/ wa3-key1, wa3-key2,wa3-var.
endloop.
Hope it helps.
Regards,
Chris Gu -
Left Outer Join on same table clarification
HI,
I have a table that gets populated from 3<sup>rd</sup> party system. We don’t have control over it. So, the table has master record (master) and children. Master type is 78 and children’s type is 64. So, it looks like this. In the 3<sup>rd</sup>
party system, if Master transaction gets cancelled, it is recorded as type 178. If child is cancelled, then it is 164. Once the child is cancelled and created again using one process then newly created transaction will have 65 as type. Same thing with Master
cancelled transaction also. It will be 79. So, to summarize:
Master:
Brand New Transaction type = 78
Cancelled Transaction type = 178
Cancelled with creation transaction type = 79
Child:
Brand New Transaction type = 64
Cancelled Transaction type = 164
Cancelled with creation transaction type = 65
I don’t have to bother about master records. I need to focus on only children for my query.
ID
TxnID
Master
Type
TDate
Location
193075
211554
211543
64
20140805
ABC
193076
211555
211543
64
20140805
NBC
193077
211556
211543
64
20140805
ABC
193080
211559
211558
64
20140805
ABC
193081
211562
211561
64
20140805
ABC
193082
211565
211564
64
20140805
CBC
193083
211565
211564
164
20140805
CBC
193084
211566
211564
65
20140805
AZC
--drop
table #Transactions
CREATE
TABLE #Transactions
ID
int,
TxnID
int,
mstTicket
int,
Typecode
int,
Tdate
datetime,
Location
varchar(10)
select
* from
#Transactions
Insert
into #Transactions
(ID,
TxnID,
mstTicket,Typecode,Tdate,Location)
Select 193075, 211554,211543,64,'2014-08-05','ABC'
UNION ALL
Select 193076, 211555,211543, 64,
'2014-08-05',
'NBC' UNION ALL
Select 193077, 211556, 211543, 64,
'2014-08-05',
'ABC' UNION
ALL
Select 193080, 211559, 211558, 64,
'2014-08-05',
'ABC' UNION
ALL
Select 193081, 211562, 211561, 64,
'2014-08-05',
'ABC' UNION
ALL
Select 193082, 211565, 211564, 64,
'2014-08-05',
'CBC' UNION
ALL
Select 193083, 211565, 211564, 164,
'2014-08-05',
'CBC' UNION
ALL
Select 193084, 211566, 211564, 65,
'2014-08-05',
'AZC'
select
T.TxnID,
T.TypeCode,
T.Location,
TL.TxnID
From
#Transactions T
Left Outer
JOIN #Transactions
TL ON
TL.TxnID
= T.TxnID
and TL.TypeCode
= 164
select
T.TxnID,
T.TypeCode,
T.Location,
TL.TxnID
From
#Transactions T
Left Outer
JOIN #Transactions
TL ON
TL.TxnID
= T.TxnID
and TL.TypeCode
= 164
Where
T.typecode
in (64, 65)
I need a clarification regarding left Outer Join.
In the first left outer join query both 64 and 164 both have TL.TxnID populated. Why is that?. What I understand from
left outer join is that ‘Returns all the rows’ from left table and only matching data from right table.
Here, matching row from right table is 211565 and 164 record (id 193083). So, only it should have TxnID populated. But row 211565 and 64 has TL.txnID getting populated (ID 193082).
Why is it? Am I not understanding left out join properly?
Thanks,Thank you Shailesh. I understood what join does in left outer join. I was thinking
Left Outer JOIN #Transactions TL ON TL.TxnID = T.TxnID and TL.TypeCode = 164 is same as
Left Outer JOIN #Transactions TL ON TL.TxnID = T.TxnID and TL.TypeCode = T.TypeCode
and TL.TypeCode = 164
#Transactions
T
Left
Outer
JOIN
#Transactions
TL
ON
TL.TxnID
=
T.TxnID
and
TL.TypeCode
= 164
Where
T.typecode
in
(64,
65) -
I am dealing with a nested table (I simplified the case
for purpose of posting):
CREATE TABLE boris_main_tab (
IND_SSN VARCHAR2(9) PRIMARY KEY,
children B_CHILDREN_TBL,
) nested table children stored as....
where B_CHILDREN_TBL is defined like this:
create or replace type b_children_type as object (
child_ssn VARCHAR2(9),
child_first_name VARCHAR2(20),
child_last_name VARCHAR2(20),
child_dob date
create or replace type b_children_tbl as table of b_children_type;
if I want to display person's ssn along with his/her children information I do like this:
SELECT m.ind_ssn, c.child_ssn, c.child_first_name
FROM boris_main_tab m,
TABLE(m.children) c
This is a statement I can find everywhere. But there is a caveat here, they
forgot to mention. This is really an inner join, so I don't get childless
people. Can you, guys, help me with the outer join syntax?
I mean, of course, I found the obvious solution to make this inner join
into a view and then join it with the boris_main_tab again this time using the
regular outer join syntax. But it seems to me there has to be something simplier than that.
But I can't find it. It really hurting me, since I have a few nested table
columsn and people want to see the records where I need to mention a few of
them, sort of like
from boris_main_tab m, TABLE(m.children) c, TABLE(m.spouses) s
where c.child_last_name <> m.spouse.last_name
in cases like this the fact that EACH of these joins is inner join really
hurts the logic.
Respectfully,
BorisHi Borris,
Found the following in the Oracle Documentation under: Oracle8i Application Developer's Guide - Object-Relational Features Release 2 (8.1.6)
2 Managing Oracle Objects / Using Collections / Collection Unnesting
URL: http://www.znow.com/sales/oracle/appdev.816/a76976/adobjmng.htm#1002885
Oracle8i also supports the following syntax to produce outer-join results:
SELECT d.*, e.* FROM depts d, TABLE(d.emps)(+) e;
The (+) indicates that the dependent join between DEPTS and D.EMPS should be NULL-augmented. That is, there > will be rows of DEPTS in the output for which D.EMPS is NULL or empty, with NULL values for columns
corresponding to D.EMPS. -
Records getting multiplied by a factor of 3 when joining with other table
When i query a table association_1 records for a particular network element i get 7 records
but join it with rtts_association table to get the rtts_no i m getting 21 records.....
the problems is ... 7 records are getting multiplied by a factor of 3 resulting in 21 records ....
how can i avoid these extra records that appear in the second query
SQL> select raised,cleared from association_1 where ne ='30434000/1MU';
RAISED CLEARED
03-FEB-2011 22:03:10 03-FEB-2011 22:06:15
12-FEB-2011 06:27:18 12-FEB-2011 06:29:51
21-FEB-2011 21:36:44 22-FEB-2011 10:23:06
23-FEB-2011 01:08:44 23-FEB-2011 06:56:53
23-FEB-2011 17:06:16 23-FEB-2011 19:55:19
23-FEB-2011 20:37:22 23-FEB-2011 23:01:21
24-FEB-2011 00:33:17 24-FEB-2011 02:03:26
SQL> select a.raised,a.cleared,b.rtts from association_1 a, rtts_association b where a.ne=b.ne and a.ne='30434000/1MU';
RAISED CLEARED RTTS
03-FEB-2011 22:03:10 03-FEB-2011 22:06:15 1490980
03-FEB-2011 22:03:10 03-FEB-2011 22:06:15 1487697
03-FEB-2011 22:03:10 03-FEB-2011 22:06:15 1487649
12-FEB-2011 06:27:18 12-FEB-2011 06:29:51 1490980
12-FEB-2011 06:27:18 12-FEB-2011 06:29:51 1487697
12-FEB-2011 06:27:18 12-FEB-2011 06:29:51 1487649
21-FEB-2011 21:36:44 22-FEB-2011 10:23:06 1490980
21-FEB-2011 21:36:44 22-FEB-2011 10:23:06 1487697
21-FEB-2011 21:36:44 22-FEB-2011 10:23:06 1487649
23-FEB-2011 01:08:44 23-FEB-2011 06:56:53 1490980
23-FEB-2011 01:08:44 23-FEB-2011 06:56:53 1487697
RAISED CLEARED RTTS
23-FEB-2011 01:08:44 23-FEB-2011 06:56:53 1487649
23-FEB-2011 17:06:16 23-FEB-2011 19:55:19 1490980
23-FEB-2011 17:06:16 23-FEB-2011 19:55:19 1487697
23-FEB-2011 17:06:16 23-FEB-2011 19:55:19 1487649
23-FEB-2011 20:37:22 23-FEB-2011 23:01:21 1490980
23-FEB-2011 20:37:22 23-FEB-2011 23:01:21 1487697
23-FEB-2011 20:37:22 23-FEB-2011 23:01:21 1487649
24-FEB-2011 00:33:17 24-FEB-2011 02:03:26 1490980
24-FEB-2011 00:33:17 24-FEB-2011 02:03:26 1487697
24-FEB-2011 00:33:17 24-FEB-2011 02:03:26 1487649
21 rows selected.For every combination of raised & cleared columns in "association_1" table, there are 3 records in the "rtts_association" table with different values for "RTTS" as below:
Association_1:
RAISED CLEARED
03-FEB-2011 22:03:10 03-FEB-2011 22:06:15
rtts_association
03-FEB-2011 22:03:10 03-FEB-2011 22:06:15 1490980
03-FEB-2011 22:03:10 03-FEB-2011 22:06:15 1487697
03-FEB-2011 22:03:10 03-FEB-2011 22:06:15 1487649Hence, evidently you wil get 7 (association_1) * 3 (rtts_association) in your output. If you want only one record in the output, you may need to pick any one of the values of RTTS from the 3 different values based on a pre-defined condition (e.g. record corresponding to lowest or highest value of RTTS)
Cheers -- -
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 -
Fact table is joining with Other table having values for measures
I have one Fact table named Fact1 where i am going to create some calculation measures based on the values in Table2.
How should be the physical join between them and the logical join.
Earlier we had those VALUES in Fact1 only
Why we created table Table2 is there was bit confusion for the aggregation in Fact1.
We are bit confused on whether to make Table2 as dimension or Fact as it is having some measures and not having the foreign keys
How we have to proceed now..!! Please help us!!?I have one Fact table named Fact1 where i am going to create some calculation measures based on the values in Table2.
How should be the physical join between them and the logical join.
Earlier we had those VALUES in Fact1 only
Why we created table Table2 is there was bit confusion for the aggregation in Fact1.
We are bit confused on whether to make Table2 as dimension or Fact as it is having some measures and not having the foreign keys
How we have to proceed now..!! Please help us!!? -
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 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
Maybe you are looking for
-
How to keep vertically arranged fields to print on the same page?
Hello, my report contains fields that are vertically arranged. I want the report to print all the fields on the same page and not if the page is too small at the end that the half of the fields are printed on one page and the rest on the next page.
-
Concatenate : extract from non-SAP
Hello All, I am extracting some records from a non-SAP system via XI. The problem is with the 0UNIT field. data from SIBEL is stored as "Hou" (hours) but in BW we can only use "H". Can any one tell me how can i transform "hou" to "h"in BW. any syntax
-
In weblogic 10.3, is it possible to set java arguments by using the console only? I tried to put: -DmyArg=XXX inside the Arguments section of my weblogic server under the tab "Server start". However, when I start the server and look at the logs, the
-
Working with "property nodes" in pda module
Hi, i already know that it is not possible to work with property node in pda module. I have found something that allows to replace the visible property node (LabVIEW_PDA_Module_Property_Additions), but i need other property nodes. I need the followin
-
Excessive memory usage by app after moving to 8.1.7.8 drivers
Good day all, I'm currently working with an app that communicates with an Oracle 8.1.7 database. The app is running on a WinXP system and the Oracle database is running on Win2K. After upgrading the ODBC oracle drivers the app utilizes from 8.1.7.6 t