Help Required in full outer Join
I feel the below query can be changed to full outer join. But, I've not been able to do so.
I require your help in changing it to full outer join. My current query is
SELECT CLAIMNO,'1' INDX FROM D_CLAIM@CMS2PROD
WHERE clntsys=76500 and facility=76501 and filecreatedt='18-feb-2011' and fileupdatedt is null
MINUS
SELECT CLAIMNO,'1' FROM D_CLAIM
WHERE clntsys=76500 and facility=76501 and filecreatedt='18-feb-2011' and fileupdatedt is null
UNION
SELECT CLAIMNO,'2' FROM D_CLAIM
WHERE clntsys=76500 and facility=76501 and filecreatedt='18-feb-2011' and fileupdatedt is null
MINUS
SELECT CLAIMNO,'2' FROM D_CLAIM@cms2prod
WHERE clntsys=76500 and facility=76501 and filecreatedt='18-feb-2011' and fileupdatedt is null
donisback wrote:
I feel the below query can be changed to full outer join. But, I've not been able to do so.
I require your help in changing it to full outer join. My current query is
SELECT CLAIMNO,'1' INDX FROM D_CLAIM@CMS2PROD
WHERE clntsys=76500 and facility=76501 and filecreatedt='18-feb-2011' and fileupdatedt is null
MINUS
SELECT CLAIMNO,'1' FROM D_CLAIM
WHERE clntsys=76500 and facility=76501 and filecreatedt='18-feb-2011' and fileupdatedt is null
UNION
SELECT CLAIMNO,'2' FROM D_CLAIM
WHERE clntsys=76500 and facility=76501 and filecreatedt='18-feb-2011' and fileupdatedt is null
MINUS
SELECT CLAIMNO,'2' FROM D_CLAIM@cms2prod
WHERE clntsys=76500 and facility=76501 and filecreatedt='18-feb-2011' and fileupdatedt is null
I do not think that query is doing what you think that it is doing - on first inspection, it was not doing what I thought either due to the order in which the UNION and MINUS operators are performed. If the FILECREATEDT column is defined as a DATE, your query is relying on an implicit date conversion - in such a case, you should replace:
filecreatedt='18-feb-2011'With:
filecreatedt=TO_DATE('18-feb-2011','DD-MON-YYYY')Now, building a simple model to explain what is happening, we create two tables with 10 rows each. The first table has C1 values that increase by 2, while the second has C1 values that increase by 3:
CREATE TABLE T1 AS
SELECT
ROWNUM*2 C1,
TRUNC(SYSDATE)+ROWNUM*2 C2
FROM
DUAL
CONNECT BY
LEVEL<=10;
CREATE TABLE T2 AS
SELECT
ROWNUM*3 C1,
TRUNC(SYSDATE)+ROWNUM*3 C2
FROM
DUAL
CONNECT BY
LEVEL<=10;It appears that the intended result of your query is to obtain a distinct list of those rows that are in each table that are not in both tables - the UNION ALL minus the intersection of the rows in two tables. However, that is not what you are achieving with that query. To demonstrate, the two halves of your query:
SELECT
C1,
C2
FROM
T1
MINUS
SELECT
C1,
C2
FROM
T2;
C1 C2
2 28-FEB-11
4 02-MAR-11
8 06-MAR-11
10 08-MAR-11
14 12-MAR-11
16 14-MAR-11
20 18-MAR-11
SELECT
C1,
C2
FROM
T2
MINUS
SELECT
C1,
C2
FROM
T1;
C1 C2
3 01-MAR-11
9 07-MAR-11
15 13-MAR-11
21 19-MAR-11
24 22-MAR-11
27 25-MAR-11
30 28-MAR-11As can be seen by the above, each half returned 7 rows - there are 7 rows in each table that is not in the other table. Common sense would state that if we UNION these two results (assuming no duplicate values in each table), we would see 14 rows:
SELECT
C1,
C2
FROM
T1
MINUS
SELECT
C1,
C2
FROM
T2
UNION
SELECT
C1,
C2
FROM
T2
MINUS
SELECT
C1,
C2
FROM
T1;
C1 C2
3 01-MAR-11
9 07-MAR-11
15 13-MAR-11
21 19-MAR-11
24 22-MAR-11
27 25-MAR-11
30 28-MAR-11Only 7 rows? Let's try again with the help of inline views to control the order in which the MINUS and UNION operators are processed:
SELECT
FROM
(SELECT
C1,
C2
FROM
T1
MINUS
SELECT
C1,
C2
FROM
T2)
UNION
SELECT
FROM
(SELECT
C1,
C2
FROM
T2
MINUS
SELECT
C1,
C2
FROM
T1);
C1 C2
2 28-FEB-11
3 01-MAR-11
4 02-MAR-11
8 06-MAR-11
9 07-MAR-11
10 08-MAR-11
14 12-MAR-11
15 13-MAR-11
16 14-MAR-11
20 18-MAR-11
21 19-MAR-11
24 22-MAR-11
27 25-MAR-11
30 28-MAR-11Note that the above returned 14 rows. We can do the same using just two outer joins:
SELECT
T1.C1,
T1.C2
FROM
T1,
T2
WHERE
T1.C1=T2.C1(+)
AND T2.C1 IS NULL
UNION
SELECT
T2.C1,
T2.C2
FROM
T1,
T2
WHERE
T2.C1=T1.C1(+)
AND T1.C1 IS NULL;
C1 C2
2 28-FEB-11
3 01-MAR-11
4 02-MAR-11
8 06-MAR-11
9 07-MAR-11
10 08-MAR-11
14 12-MAR-11
15 13-MAR-11
16 14-MAR-11
20 18-MAR-11
21 19-MAR-11
24 22-MAR-11
27 25-MAR-11
30 28-MAR-11Or we can do it with a full outer join and a MINUS operator:
SELECT
NVL(T1.C1,T2.C1) C1,
NVL2(T1.C1,T1.C2,T2.C2) C2
FROM
T1 FULL OUTER JOIN T2
ON T1.C1=T2.C1
MINUS
SELECT
T1.C1,
T1.C2
FROM
T1,
T2
WHERE
T1.C1=T2.C1;
C1 C2
2 28-FEB-11
3 01-MAR-11
4 02-MAR-11
8 06-MAR-11
9 07-MAR-11
10 08-MAR-11
14 12-MAR-11
15 13-MAR-11
16 14-MAR-11
20 18-MAR-11
21 19-MAR-11
24 22-MAR-11
27 25-MAR-11
30 28-MAR-11Or just with a full outer join with a WHERE clause:
SELECT
NVL(T1.C1,T2.C1) C1,
NVL2(T1.C1,T1.C2,T2.C2) C2
FROM
T1 FULL OUTER JOIN T2
ON T1.C1=T2.C1
WHERE
(T1.C1 IS NULL
OR T2.C1 IS NULL);
C1 C2
3 01-MAR-11
9 07-MAR-11
15 13-MAR-11
21 19-MAR-11
24 22-MAR-11
27 25-MAR-11
30 28-MAR-11
8 06-MAR-11
20 18-MAR-11
2 28-FEB-11
10 08-MAR-11
4 02-MAR-11
14 12-MAR-11
16 14-MAR-11With the above knowledge, you should be able to fix your SQL statement to produce the expected results.
Charles Hooper
Co-author of "Expert Oracle Practices: Oracle Database Administration from the Oak Table"
http://hoopercharles.wordpress.com/
IT Manager/Oracle DBA
K&M Machine-Fabricating, Inc.
Similar Messages
-
SQL Query Assistance Required for Full Outer Join
Hi,
Lets say I have two tables, i.e:
TAB_A (colA1, colA2, colA3, colA4)
TAB_B (colB1, colB2, colB3, colB4) where colB2 is a FK to colA1
I am after an SQL query that will cater for both the following two scenarios.
Scenario 1:
TAB_A has two rows of data, i.e
(1, ABC100, 1, WG_A)
(2, ABC100, 2, WG_B)
TAB_B has one row of data, i.e
(1, 1, EMP_222, 4)
I use the following SQL:
select a.*, b.*
from tab_a a FULL OUTER JOIN tab_b b ON (a.colA1 = b.colB2)
where a.colA2 = 'ABC100'
This returns two rows:
1, ABC100, 1, WG_A, 1, 1, EMP_222, 4
2, ABC100, 2, WG_B
Now, what I actually would like my query to do is actually only return the row where a tab_b record exists, i.e, should only return one record:
1, ABC100, 1, WG_A, 1, 1, EMP_222, 4
This I can achieve by using a RIGHT OUTER JOIN instead above, but this causes issue with my scenario 2, which is the following set-up
Scenario 2:
TAB_A has only one row of data this time, i.e
(2, ABC100, 2, WG_B)
TAB_B has no data at all this time
This returns no rows but I actually now want this single record from tab_a returned.
I basically require an SQL query that will cater for both the top 2 scenarios, i.e, if a tab_b record exists from the outer join then only return this record along with tab_a data. If a tab_b record doesn't exist, then only return the tab_a record.
Hope the above makes sense.
Thanks.Is it what you need (not very elegant) ?
SQL> select * from t_outer;
ID CODE
1 100
2 100
SQL> select * from t_inner;
no rows selected
SQL> with tab1 as (
2 select a.id a_id, a.code, b.id b_id from t_outer a join t_inner b on
3 (a.id = b.id and a.code = '100'))
4 select * from tab1
5 union all
6 select a.*, null from t_outer a where not exists (
7 select 1 from tab1)
8 and a.code = '100'
9 /
A_ID CODE B_ID
1 100
2 100
SQL> insert into t_inner values(2);
1 row created.
SQL> with tab1 as (
2 select a.id a_id, a.code, b.id b_id from t_outer a join t_inner b on
3 (a.id = b.id and a.code = '100'))
4 select * from tab1
5 union all
6 select a.*, null from t_outer a where not exists (
7 select 1 from tab1)
8 and a.code = '100'
9 /
A_ID CODE B_ID
2 100 2
Rgds. -
Help Required with an OUTER JOIN Query
Hi,
I need a list of records carrying UserID and ALL SectionIDs and SectionTitles he/she is associated
with so I created following query:
SELECT UsersSections.UserID, Sections.SectionID, Sections.SectionTitle
FROM UsersSections, Sections
WHERE UsersSections.SectionID(+) = Sections.SectionID AND UsersSections.UserID = 1
Where my tables are:
- UsersSections (UserID, SectionID)
- Sections (SectionID, SectionTitle)
The problem is that if I exclude WHERE UserID = '1' clause the query return the desired result i.e. ALL Sections
And ALL Users associated with the any Section(s). But I need results for a particular UserID but
Including WHERE UserID = '1' clause only return records for that User only not the sections he/she belongs to which was the purpose of using OUTER JOIN.
Any help will be highly appreciated.
Thanks.
AKGuserssections.userid (+) = 1
-
Using : Oracle 11.2.0.1 on Windows XP
create table tab40(bno varchar2(1),pno varchar2(7),weight number(3),lineno number(3));
insert into tab40 values ('1','1115027',36,1);
insert into tab40 values ('2','1115100',25,2);
insert into tab40 values ('3','1115200',50,3);
insert into tab40 values ('1','1112510',60,4);
insert into tab40 values ('+','1112610',6,5);
insert into tab40 values ('+','1112710',4,6);
insert into tab40 values ('+','1110710',1,7);
insert into tab40 values ('2','1117014',79,8);
insert into tab40 values ('+','1117000',9,9);
insert into tab40 values ('+','1117001',2,10);
insert into tab40 values ('1','1317001',200,11);
insert into tab40 values ('1','1697001',20,12);
insert into tab40 values ('2','2997001',40,13);
insert into tab40 values ('1','2996001',44,14);
SQL> select * from tab40;
B PNO WEIGHT LINENO
1 1115027 36 1
2 1115100 25 2
3 1115200 50 3
1 1112510 60 4
+ 1112610 6 5
+ 1112710 4 6
+ 1110710 1 7
2 1117014 79 8
+ 1117000 9 9
+ 1117001 2 10
1 1317001 200 11
B PNO WEIGHT LINENO
1 1697001 20 12
2 2997001 40 13
1 2996001 44 14
14 rows selected.
SQL>create table tab41(bno varchar2(1),pno varchar2(7),weight number(3),lineno number(3));
insert into tab41 values ('1','1115027',36,1);
insert into tab41 values ('2','1115100',25,2);
insert into tab41 values ('3','1115200',50,3);
insert into tab41 values ('1','1112510',60,4);
insert into tab41 values ('+','1112610',6,5);
insert into tab41 values ('+','1110710',1,6);
insert into tab41 values ('2','1117014',79,7);
insert into tab41 values ('+','1117000',9,8);
insert into tab41 values ('1','1317001',200,9);
insert into tab41 values ('1','1697001',20,10);
insert into tab41 values ('2','2997001',40,11);
insert into tab41 values ('1','2996001',44,12);
insert into tab41 values ('+','1112710',4,13);
insert into tab41 values ('+','3332710',8,14);
SQL> select * from tab41;
B PNO WEIGHT LINENO
1 1115027 36 1
2 1115100 25 2
3 1115200 50 3
1 1112510 60 4
+ 1112610 6 5
+ 1110710 1 6
2 1117014 79 7
+ 1117000 9 8
1 1317001 200 9
1 1697001 20 10
2 2997001 40 11
B PNO WEIGHT LINENO
1 2996001 44 12
+ 1112710 4 13
+ 3332710 8 14
14 rows selected.
SQL>Required Output :
A B C D E F G H
1 1112510 60 4 1 2996001 44 12
+ 1112710 4 6 + 1112710 4 13
2 1117014 79 8
+ 1117001 2 10
1 2996001 44 12
+ 3332710 8 14Logic : The plus sign in Bno indicates that Packet No. was sent to customer with last non plus signed number packet (order by lineno) i.e. for example in tab40 there is line no. 6 whose master packet number is 1112510 (previous non plus signed rows's PNO). Now come to required output; which is showing that these plus signed packets (whose master PNO is that) are not as per tab40 vs tab41 something like full outer join between tab40 and tab41. Example :
+ 1112710 is associated with 1112510 in tab40, while in tab41 it is associated with 2996001; so it is difference.
+ 1117001 is associated with 1117014 in tab40, while it is not in tab41.
vice versa;
+ 3332710 is associated with 2996001 in tab41, while it is not in tab40.
I mean, if only plus marked row's PNO's mater packet number is not equal to master PNO(previous non plus marked BNO) in both the table, it should be part of the select query please. Generally this happens, when our packing department gets late delivery of prior master packet, so they just send the small packet with immediate available one (non plus) packet.
Kindly let me; i am clear in my request or i should elaborate more. This may be more complex, because may be bad table/data design, but i need the output by select query please help me.
Regards.
Edited by: user12050217 on Jan 3, 2012 3:57 AMYes, you have perfectly understood my question... just i added lineno > 1
SELECT bno,
pno,
weight,
lineno
FROM ( SELECT tab40.*, lag (bno) OVER (ORDER BY pno) prev_bno
FROM tab40
ORDER BY pno)
WHERE bno = '+' OR prev_bno = '+' and lineno > 1
ORDER BY lineno
and it worked, because there are no chances that plus marked row will be having lineno <=1
B PNO WEIGHT LINENO
1 1112510 60 4
+ 1112610 6 5
+ 1112710 4 6
+ 1110710 1 7
2 1117014 79 8
+ 1117000 9 9
+ 1117001 2 10
7 rows selected. -
Query with FULL OUTER JOIN , help pleaseeeeeeeeeeee...
Hi everyone,
I'm trying to write a query for a report in Oracle SQL, but i just can't figure out how to do it.
I'm using Oracle 10g release 1.0 database and i execute my queris in SQL* PLUS ( eventually i'm gonna use them in Oracle Report Builder ) .
here's what i have:
i have four tables that are used for our inventory application. lets call them INCOMMING , INCOMMING_ITEMS , OUTGOING , OUTGOING_ITEMS.
as you may have guessed , INCOMMING_ITEMS is the detail table for INCOMMING ( joined by IID column) and also OUTGOING_ITEMS is the detail table for OUTGOING ( joined by OID column ).
here is the structure of them :
INCOMMING
IID varchar2
CDATE date
INCOMMING_ITEM
IID varchar2
PART_NO number
QTY number
OUTGOING
OID varchar2
CDATE date
OUTGOING_ITEM
OID varchar2
PART_NO number
QTY number
now , the query i want, should return part_no , cdate , sum of OUTGOING qty , sum of INCOMMING qty .
the result of the query should be sth like this :
part_no cdate O_qty I_qty
100 01/05/06 10 0
100 01/05/07 20 60
200 01/06/02 0 50
300 01/06/02 30 40
this means that for some dates and for some parts, i may not have INCOMMING or OUTGOING data, but if at least one of the 2 last columns has a non-zero data, i should show the row ( like the first and third rows of my example result), and if both have data for the same PART_NO and the same CDATE, both should be showed in the same row. ( like the second row in my example result)
i tried so much and came up with several huge and also time consuming queries, but then i read abt FULL OUTER JOIN somewhere and tried using that. here is what i came up with :
SELECT
PART_NO , CDATE , sum(II.QTY) I_QTY , SUM (OI.QTY) O_QTY
FROM
(OUTGOING O INNER JOIN OUTGOING_ITEM OI USING ( OID ) )
FULL OUTER JOIN
(INCOMMING I INNER JOIN INCOMMING_ITEM II USING ( IID ) )
ON ( I.CDATE = O.CDATE AND II.PART_NO = OI.PART_NO)
WHERE
I.CDATE = :PARAMETER1
AND O.CDATE = :PARAMETER1
GROUP BY
PART_NO , CDATE
this query is short and fast , but the results r not what i expected. i mean, although i have used FULL OUTER JOIN in the query , but the results i get r sth like this :
part_no cdate O_qty I_qty
100 01/05/07 20 60
300 01/06/02 30 40
which means only the rows that has both values are returned.
any change i make to this query would make the SQL* PLUS hang , like when i use the cartesian product of two large tables, so i guess my changes wheren't in the right direction.
i think its possible to write this query using FULL OUTER JOIN syntax, but i just can't find it.
Can anybody pleaseeeeeeeeeeeee help me?
thanx in advance,
Maryam.Note: I wrote this on the fly -- hope there is no syntax errors, otherwise forgive me -- but you get the idea..
select
fromUnionAll.cdate, fromUnionAll.part_no,
sum(fromUnionAll.O_qty) O_qty,
sum(fromUnionAll.I_qty) I_qty
from
select
iinner.cdate, iinner.part_no, 0 O_qty, iinner.I_qty
from
select
i.cdate, ii.part_no,
/* added the case only for the extreme case when there is
no record anywhere for the given CDATE in INCOMMING_item */
sum( ( case when ii.qty is not null then ii.qty else 0 end) ) I_qty
from
incomming i,
incomming_item ii
where
i.iid = ii.iid (+)
group by i.cdate, ii.part_no
) iinner
union all
select
oinner.cdate, oinner.part_no, oinner.O_qty, 0 I_qty
from
select
o.cdate, oi.part_no,
/* added the case only for the extreme case when there is
no record anywhere for the given CDATE in OUTGOING_item */
sum( ( case when oi.qty is not null then oi.qty else 0 end) ) O_qty
from
outgoing o,
outgoing_item oi
where
o.oid = oi.oid (+)
group by o.cdate, oi.part_no
) oinner
) fromUnionAll
group by fromUnionAll.cdate, fromUnionAll.part_no;
--Samson -
Reg: Full outer join help pls
hi friends,
i have created the following query using full outer join
pls help me.
Thanks
Rajesh
Message was edited by:
Rajesh.maniI'm not sure if there should be a AND before FULL OUTER JOIN clause. I've always been reluctant to use ANSI syntax. here you can check the actual syntax. Bu then, from now on, try to keep quote your query between [pre] and [/pre] tags to preserve the format.
Cheers
Sarma. -
Hi All,
I am new to crystal and my sql.
l have 2 command objects in that i have a common column pos_no.Now i need to apply Fullouterjoin between pos_no,but in crystal we don,t have that option.
So i saw some threads that we need to apply leftouterjoin union rightouterjoin to get FOJ in db level ,i tried ,but i don't have much knowledge in my sql.So can any one please apply FOJ between Pos_no of these two queries.
Please help me i strucked here
1st Query:
select
MIN(till_close.start_transaction_id) AS start_trans_id,
MAX(till_close.end_transaction_id) AS end_trans_id,
pos_config.pos_no,
pos_config.name AS pos_name,
SUM(transaction_tender.amount) AS EodDeposit
FROM
till_close
LEFT OUTER JOIN employee ON (till_close.employee_id = employee.employee_id)
INNER JOIN pos_config ON (till_close.pos_config_id = pos_config.pos_config_id)
INNER JOIN transaction_tender ON (till_close.end_transaction_id = transaction_tender.transaction_id)
INNER JOIN media_type ON (transaction_tender.media_type_id = media_type.media_type_id)
WHERE
DATE_FORMAT(till_close.transaction_date,'%d/%m/%Y') = DATE_FORMAT(STR_TO_DATE(?,'%d/%m/%Y'),'%d/%m/%Y')
AND transaction_tender.media_type_id NOT IN (10000)
GROUP BY
pos_config.pos_no
ORDER BY
pos_config.pos_no
2nd Query:
select
pos_config.pos_no,
pos_config.name AS pos_name,
SUM(CASE WHEN transaction.transaction_type_id=7 AND ((SELECT COUNT(transaction_id) FROM transaction_tender WHERE transaction_id = transaction.transaction_id AND media_type_id IN (SELECT media_type_id FROM media_type WHERE tender_type_id=12) AND amount < 0 )>0) THEN 0
WHEN transaction_tender.balance < 0
THEN transaction_tender.amount
ELSE (transaction_tender.amount - transaction_tender.balance)
END) AS net
FROM
TRANSACTION
INNER JOIN transaction_tender ON (transaction.transaction_id = transaction_tender.transaction_id)
INNER JOIN media_type ON (transaction_tender.media_type_id = media_type.media_type_id)
INNER JOIN pos_config ON (transaction.pos_config_id = pos_config.pos_config_id)
WHERE
transaction.transaction_date = DATE_FORMAT(STR_TO_DATE(?, '%d/%m/%Y'), '%Y-%m-%d')
AND transaction.transaction_type_id IN (1,5,7)
AND transaction.transaction_status_id = 3
AND transaction.is_training_mode = 0
GROUP BY
pos_config.pos_nohi Divya,
i would definitely take the advice from the folks here on a rewrite of your commands into one command.
since you've got 2 commands that are bringing back different results you may wish to consider bringing back the results from the 2nd command via a sub-query.
the general idea of the query is below, but you'll need to consult your online help for your database and or your dba for the correct syntax for your situation.
notes:
1) the subselect is in the bold font and is defined as a result set in the join...again, please consult your database help or the appropriated forum for your database as your syntax may vary
2) the fields in the subquery are then referenced in the select clause using the TT alias assigned to the result set in the join
3) the full outer join i guessed that you wanted on the two pos_no fields
4) if you do try to do this method and are looking on your database forum, do a search on "subquery multiple columns"
cheers,
jamie
select
MIN(till_close.start_transaction_id) AS start_trans_id,
MAX(till_close.end_transaction_id) AS end_trans_id,
pos_config.pos_no AS PC_pos_no,
pos_config.name AS pos_name AS PC_pos_name,
SUM(transaction_tender.amount) AS EodDeposit,
TT.pos_no AS TT_pos_no,
TT.pos_name AS TT_pos_name,
TT.net
FROM
till_close
LEFT OUTER JOIN employee ON (till_close.employee_id = employee.employee_id)
INNER JOIN pos_config ON (till_close.pos_config_id = pos_config.pos_config_id)
INNER JOIN transaction_tender ON (till_close.end_transaction_id = transaction_tender.transaction_id)
INNER JOIN media_type ON (transaction_tender.media_type_id = media_type.media_type_id)
FULL OUTER JOIN
(select
pos_config.pos_no,
pos_config.pos_name,
SUM(CASE WHEN transaction.transaction_type_id=7 AND ((SELECT COUNT(transaction_id) FROM transaction_tender WHERE transaction_id = transaction.transaction_id AND media_type_id IN (SELECT media_type_id FROM media_type WHERE tender_type_id=12) AND amount < 0 )>0) THEN 0
WHEN transaction_tender.balance < 0
THEN transaction_tender.amount
ELSE (transaction_tender.amount - transaction_tender.balance)
END) AS net
FROM
TRANSACTION
INNER JOIN transaction_tender ON (transaction.transaction_id = transaction_tender.transaction_id)
INNER JOIN media_type ON (transaction_tender.media_type_id = media_type.media_type_id)
INNER JOIN pos_config ON (transaction.pos_config_id = pos_config.pos_config_id)
WHERE
transaction.transaction_date = DATE_FORMAT(STR_TO_DATE(?, '%d/%m/%Y'), '%Y-%m-%d')
AND transaction.transaction_type_id IN (1,5,7)
AND transaction.transaction_status_id = 3
AND transaction.is_training_mode = 0
GROUP BY
pos_config.pos_no) AS TT
ON TT.pos_no = pos_config.pos_no
WHERE
DATE_FORMAT(till_close.transaction_date,'%d/%m/%Y') = DATE_FORMAT(STR_TO_DATE(?,'%d/%m/%Y'),'%d/%m/%Y')
AND transaction_tender.media_type_id NOT IN (10000)
GROUP BY
pos_config.pos_no
ORDER BY
pos_config.pos_no -
I can't figure out how to combine a full outer join with another type of join ... is this possible?
Here's some create table and insert statements for some basic sample data:
CREATE TABLE my_tab1
( record_id NUMBER NOT NULL
, workstation VARCHAR2(4)
, my_value NUMBER
CONSTRAINT my_tab1_pk PRIMARY KEY (record_id)
INSERT INTO my_tab1
VALUES(1,'ABCD',10);
INSERT INTO my_tab1
VALUES(2,'ABCD',15);
INSERT INTO my_tab1
VALUES(3,'ABCD',5);
INSERT INTO my_tab1
VALUES(4,'A123',5);
INSERT INTO my_tab1
VALUES(5,'A123',10);
INSERT INTO my_tab1
VALUES(6,'A123',20);
INSERT INTO my_tab1
VALUES(7,'????',5);
CREATE TABLE my_tab2
( workstation VARCHAR2(4)
, wkstn_name VARCHAR2(20)
CONSTRAINT my_tab2_pk PRIMARY KEY (workstation)
INSERT INTO my_tab2
VALUES('ABCD','WKSTN 1');
INSERT INTO my_tab2
VALUES('A123','WKSTN 2');
INSERT INTO my_tab2
VALUES('B456','WKSTN 3');
CREATE TABLE my_tab3
( my_nbr1 NUMBER
, my_nbr2 NUMBER
INSERT INTO my_tab3
VALUES(1,2);
INSERT INTO my_tab3
VALUES(2,3);
INSERT INTO my_tab3
VALUES(3,4);And, the results I want to get:
workstation sum(my_value) wkstn_name my_nbr1 my_nbr2
ABCD 30 WKSTN 1 1 2
ABCD 30 WKSTN 1 2 3
ABCD 30 WKSTN 1 3 4
A123 35 WKSTN 2 1 2
A123 35 WKSTN 2 2 3
A123 35 WKSTN 2 3 4
B456 0 WKSTN 3 1 2
B456 0 WKSTN 3 2 3
B456 0 WKSTN 3 3 4
???? 5 NULL 1 2
???? 5 NULL 2 3
???? 5 NULL 3 4I've tried a number of different things, googled my problem, and no luck yet...
SELECT t1.workstation
, SUM(t1.my_value)
, t2.wkstn_name
, t3.my_nbr1
, t3.my_nbr2
FROM my_tab1 t1
, my_tab2 t2
, my_tab3 t3
...So, what I want is a full outer join of t1 and t2 on workstation, and a cross-join of that with t3. I'm wondering if I can't find any examples of this online because it's not possible....
Note: I'm stuck dealing with Oracle 8i
Thanks!!Hi,
The query I posted yesterday is a little more complicated than it needs to be.
Since my_tab2.workstation is unique, there's no reason to do a separate sub-query like mt1; we can join my_tab1 to my_tab2 and get the SUM all in one sub-query.
SELECT foj.workstation
, foj.sum_my_value
, foj.wkstn_name
, mt3.my_nbr1
, mt3.my_nbr2
FROM ( -- Begin in-line view foj for full outer join
SELECT mt1.workstation
, SUM (mt1.my_value) AS sum_my_value
, mt2.wkstn_name
FROM my_tab1 mt1
, my_tab2 mt2
WHERE mt1.workstation = mt2.workstation (+)
GROUP BY mt1.workstation
, mt2.wkstn_name
UNION ALL
SELECT workstation
, 0 AS sum_my_value
, wkstn_name
FROM my_tab2
WHERE workstation NOT IN ( -- Begin NOT IN sub-query
SELECT workstation
FROM my_tab1
WHERE workstation IS NOT NULL
) -- End NOT IN sub-query
) foj -- End in-line view foj for full outer join
, my_tab3 mt3
ORDER BY foj.wkstn_name
, foj.workstation
, mt3.my_nbr1
, mt3.my_nbr2
;Thanks for posting the CREATE TABLE and INSERT statements, as well as the very clear desired results!
user11033437 wrote:
... So, what I want is a full outer join of t1 and t2 on workstation, and a cross-join of that with t3. That it, exactly!
The tricky part is how and when to get SUM (my_value). You might approach this by figuring out exactly what my_tab3 has to be cross-joined to; that is, exactly what should the result set of the full outer join between my_tab1 and my_tab2 look like. To do that, take your desired results, remove the columns that do not come from the full outer join, and remove the duplicate rows. You'll get:
workstation sum(my_value) wkstn_name
ABCD 30 WKSTN 1
A123 35 WKSTN 2
B456 0 WKSTN 3
???? 5 NULL So the core of the problem is how to get these results from my_tab1 and my_tab2, which is done in sub-query foj above.
I tried to use self-documenting names in my code. I hope you can understand it.
I could spend hours explaining different parts of this query in more detail, but I'm sure I'd waste some of that time explaining things you already understand. If you want an explanation of somthing(s) specific, let me know. -
Hi, all
Is it possible to make FULL OUTER JOIN in BI InfoSet?
If no, another question - is it possible to switch base InfoProvider? I have an InfoSet with InfoCube1 and DSO1 which I can outer join. I want to outer join InfoCube1 , not DSO1 that's why I need to switch them in the InfoSet.Hi,
In BI 7.0 Infoset has given chance to include an Info cube also,maximum you can include 2 info Cubes only in a infoset.
check the below link which helps you in understanding of the join conditions so that you can apply to your scenario.
http://help.sap.com/saphelp_nw2004s/helpdata/en/f1/713c3b35703079e10000000a114084/content.htm
http://help.sap.com/saphelp_nw2004s/helpdata/en/67/7e4b3eaf72561ee10000000a114084/content.htm
Regards,
Praveena. -
Full outer join --- bug? Urgent
Hi,
I have a simple mapping using 2 source tables and doing an full outer join. While executing the mapping it is throwing me out with an error --
Starting Execution LOAD_SAP
Starting Task LOAD_SAP
ORA-01790: expression must have same datatype as corresponding expression
ORA-02063: preceding line from ODSD@LOC_TGT_LOC_ODSD
ORA-06512: at "DWH_USER.LOAD_SAP", line 12
ORA-06512: at "DWH_USER.LOAD_SAP", line 481
ORA-06512: at "DWH_USER.LOAD_SAP", line 795
ORA-06512: at "DWH_USER.LOAD_SAP", line 1973
ORA-06512: at line 1
Completing Task LOAD_SAP
Completing Execution LOAD_SAP
The SQL generated at line 12 is -
CURSOR "JOIN_c" IS
SELECT
/*+ DRIVING_SITE("CONNECTION_LOC_TGT_LOC_ODSD") */
"CONNECTION_LOC_TGT_LOC_ODSD"."END_USER_CUST_ID" "END_USER_CUST_ID",
"SERVICE_LOC_TGT_LOC_ODSD"."SERVICE_NAME" "SERVICE_NAME",
"CONNECTION_LOC_TGT_LOC_ODSD"."CE_CLLI" "CE_CLLI",
"CONNECTION_LOC_TGT_LOC_ODSD"."PE_CLLI" "PE_CLLI"
FROM "ODS"."CONNECTION"@"ODSD"@"LOC_TGT_LOC_ODSD" "CONNECTION_LOC_TGT_LOC_ODSD"
FULL OUTER JOIN "ODS"."SERVICE"@"ODSD"@"LOC_TGT_LOC_ODSD" "SERVICE_LOC_TGT_LOC_ODSD" ON ("CONNECTION_LOC_TGT_LOC_ODSD"."END_USER_CUST_ID" = "SERVICE_LOC_TGT_LOC_ODSD"."END_USER_CUST_ID") ;
If I replace the Full outer join with an equi join everything works fine. The SQL generated with an equi-join is ---
SELECT
/*+ DRIVING_SITE("CONNECTION_LOC_TGT_LOC_ODSD") */
"CONNECTION_LOC_TGT_LOC_ODSD"."END_USER_CUST_ID" "END_USER_CUST_ID",
"SERVICE_LOC_TGT_LOC_ODSD"."SERVICE_NAME" "SERVICE_NAME",
"CONNECTION_LOC_TGT_LOC_ODSD"."CE_CLLI" "CE_CLLI",
"CONNECTION_LOC_TGT_LOC_ODSD"."PE_CLLI" "PE_CLLI"
FROM "ODS"."CONNECTION"@"ODSD"@"LOC_TGT_LOC_ODSD" "CONNECTION_LOC_TGT_LOC_ODSD",
"ODS"."SERVICE"@"ODSD"@"LOC_TGT_LOC_ODSD" "SERVICE_LOC_TGT_LOC_ODSD" WHERE ( "CONNECTION_LOC_TGT_LOC_ODSD"."END_USER_CUST_ID" = "SERVICE_LOC_TGT_LOC_ODSD"."END_USER_CUST_ID" );
We are using Oracle 9.2.0.4 AND OWB Clinet 9.2.0.2.8 and runtime repository 9.2.0.2.0.
Any help on this appreciated?The discussion on this thread has moved to the later thread Problem with JOINs
Nikolai -
How can I join/Full outer join two different columns instead of union all?
Hi,
I have a scenario as the following:
I am performing set operations using obiee 11g where I want to take values from two different criteria. Howwver, I dont want union to take place, instead i want join to take place to see all the columns in the output.
For that, I tried changing the sql in advanced tab and tried to put full outer join instead of union all but its not allowing me to change.
How can I achieve it? please help.
Thanks.Hi,
My problem is that I am unable to modify the sql in advanced tab. Probably due to some security reason,it's restricting me to change.
Can you suggest me a way to change it?
Thanks.. -
CREATE TABLE FEE_BANDS_AUD1
AUDIT_DATE TIMESTAMP (6) NOT NULL ENABLE,
AUDIT_ACTION VARCHAR2(30 BYTE) NOT NULL ENABLE,
AUDIT_USER VARCHAR2(8 BYTE) NOT NULL ENABLE,
FEE_BANDS_ID NUMBER NOT NULL ENABLE,
FEE_RULE VARCHAR2(10 BYTE) NOT NULL ENABLE,
FEE_BAND_LOWER_LIMIT NUMBER(19,0),
FEE_BAND_HIGHER_LIMIT NUMBER(19,0),
RATE_PERCENT NUMBER(11,4),
RATE_NUMBER NUMBER(21,2),
CAL_BASED_ON CHAR(1 BYTE) NOT NULL ENABLE,
REC_SEQ NUMBER(5,0) NOT NULL ENABLE)
FEE_BANDS_AUD
INSERT INTO FEE_BANDS_AUD1 VALUES('18-10-10 06:31:56.625000000 AM','CREATE','sdn',1,'NSK',0,9999999999999999999,11,0,'B',0);
INSERT INTO FEE_BANDS_AUD1 VALUES('18-10-10 06:53:08.659000000 AM','UPDATE','sdn',1,'NSK',0,100,11,0,'B',1);
INSERT INTO FEE_BANDS_AUD1 VALUES('18-10-10 06:53:08.659000000 AM','UPDATE','sdn',2,'NSK',101,9999999999999999999,1,0,'B',1);
INSERT INTO FEE_BANDS_AUD1 VALUES('18-10-10 06:54:51.354000000 AM','UPDATE','sdn',1,'NSK',0,100,11,0,'B',2);
INSERT INTO FEE_BANDS_AUD1 VALUES('18-10-10 06:54:51.354000000 AM','UPDATE','sdn',2,'NSK',101,9999999999999999999,33,0,'B',2);
INSERT INTO FEE_BANDS_AUD1 VALUES('18-10-10 07:15:16.354000000 AM','UPDATE','sdn',1,'NSK',0,100,11,0,'B',3);
INSERT INTO FEE_BANDS_AUD1 VALUES('18-10-10 07:15:16.354000000 AM','UPDATE','sdn',2,'NSK',101,200,33,0,'B',3);
INSERT INTO FEE_BANDS_AUD1 VALUES('18-10-10 07:15:16.354000000 AM','UPDATE','sdn',3,'NSK',201,9999999999999999999,1,0,'B',3);
INSERT INTO FEE_BANDS_AUD1 VALUES('18-10-10 07:15:53.341000000 AM','UPDATE','sdn',1,'NSK',0,100,11,0,'B',4);
INSERT INTO FEE_BANDS_AUD1 VALUES('18-10-10 07:15:53.341000000 AM','UPDATE','sdn',2,'NSK',101,200,33,0,'B',4);
INSERT INTO FEE_BANDS_AUD1 VALUES('18-10-10 07:15:53.341000000 AM','UPDATE','sdn',3,'NSK',201,9999999999999999999,2,0,'B',4);
INSERT INTO FEE_BANDS_AUD1 VALUES('18-10-10 07:18:52.118000000 AM','UPDATE','sdn',1,'NSK',0,100,11,0,'B',5);
INSERT INTO FEE_BANDS_AUD1 VALUES('18-10-10 07:18:52.118000000 AM','UPDATE','sdn',2,'NSK',101,9999999999999999999,2,0,'B',5); I have a bandId, in which i will update a new band or delete a band. Each time when i insert,update or delete rec_seq is incremented to one to identify the old set of bands and new set of bands.
My problem here is when i deleted a band (which is last two insert statments from the above) those are not coming in the old values . It should come in the old value set and new value should come as null.
I am using full outer join because when i create a new record there wont be any old values in this case old values should come as null and also i delete any values there wont be any new value for that so new should come as null
This is the query im trying
select
O.REC_SEQ,O.audit_action,O.fee_bands_id, O.FEE_RULE,
O.FEE_BAND_LOWER_LIMIT, O.FEE_BAND_HIGHER_LIMIT,O.CAL_BASED_ON,
N.REC_SEQ,n.audit_action,n.fee_bands_id, N.FEE_RULE,
N.FEE_BAND_LOWER_LIMIT, N.FEE_BAND_HIGHER_LIMIT,N.CAL_BASED_ON
from fee_bands_aud1 O FULL OUTER JOIN fee_bands_aud1 N
on (N.fee_bands_id = O.fee_bands_id
and N.FEE_RULE = O.FEE_RULE
and O.REC_SEQ = N.REC_SEQ-1)
where N.FEE_RULE = 'NSK'
order by N.REC_SEQ, n.fee_bands_idwhat is the problem anybody please help i am very new to oracle.Yes, it's possible.
Search for "full outer join" in the online manuals
http://tahiti.oracle.com/pls/db92/db92.drilldown?levelnum=2&toplevel=a96540&method=FULL&chapters=0&book=&wildcards=1&preference=&expand_all=&verb=&word=full+outer+join+#a96540
In the SQL Reference you can find an example -
Full outer join Bug or my misunderstanding?
CREATE GLOBAL TEMPORARY TABLE BP_ATTRIBUTE_CHARVAL_GTT
( "ATTRIBUTE_ID" NUMBER(10,0),
"PARTNER_ID" NUMBER(10,0),
"CHAR_VALUE" VARCHAR2(4000 BYTE),
"LAST_UPDATE_DATE" DATE,
"DISABLE_DATE" DATE
) ON COMMIT DEETE ROWS ;
CREATE TABLE BP_ATTRIBUTE_CHARVAL
( "ATTRIBUTE_ID" NUMBER(10,0),
"PARTNER_ID" NUMBER(10,0),
"CHAR_VALUE" VARCHAR2(4000 BYTE),
"LAST_UPDATE_DATE" DATE,
"DISABLE_DATE" DATE
REM INSERTING into BP_ATTRIBUTE_CHARVAL
Insert into BP_ATTRIBUTE_CHARVAL (ATTRIBUTE_ID,PARTNER_ID,CHAR_VALUE,LAST_UPDATE_DATE,DISABLE_DATE) values (888854,710326,'1',to_date('29-NOV-06','DD-MON-RR'),to_date('01-JAN-06','DD-MON-RR'));
Insert into BP_ATTRIBUTE_CHARVAL (ATTRIBUTE_ID,PARTNER_ID,CHAR_VALUE,LAST_UPDATE_DATE,DISABLE_DATE) values (591330,710326,'01',to_date('09-FEB-06','DD-MON-RR'),to_date('07-NOV-01','DD-MON-RR'));
Insert into BP_ATTRIBUTE_CHARVAL (ATTRIBUTE_ID,PARTNER_ID,CHAR_VALUE,LAST_UPDATE_DATE,DISABLE_DATE) values (591321,710326,'N',to_date('09-FEB-06','DD-MON-RR'),to_date('07-NOV-01','DD-MON-RR'));
Insert into BP_ATTRIBUTE_CHARVAL (ATTRIBUTE_ID,PARTNER_ID,CHAR_VALUE,LAST_UPDATE_DATE,DISABLE_DATE) values (591331,710326,'00',to_date('09-FEB-06','DD-MON-RR'),to_date('07-NOV-01','DD-MON-RR'));
Insert into BP_ATTRIBUTE_CHARVAL (ATTRIBUTE_ID,PARTNER_ID,CHAR_VALUE,LAST_UPDATE_DATE,DISABLE_DATE) values (591329,710326,'01',to_date('09-FEB-06','DD-MON-RR'),to_date('07-NOV-01','DD-MON-RR'));
Insert into BP_ATTRIBUTE_CHARVAL (ATTRIBUTE_ID,PARTNER_ID,CHAR_VALUE,LAST_UPDATE_DATE,DISABLE_DATE) values (591332,710326,'01',to_date('09-FEB-06','DD-MON-RR'),to_date('07-NOV-01','DD-MON-RR'));
Insert into BP_ATTRIBUTE_CHARVAL (ATTRIBUTE_ID,PARTNER_ID,CHAR_VALUE,LAST_UPDATE_DATE,DISABLE_DATE) values (591324,710326,'2',to_date('09-FEB-06','DD-MON-RR'),to_date('07-NOV-01','DD-MON-RR'));
Insert into BP_ATTRIBUTE_CHARVAL (ATTRIBUTE_ID,PARTNER_ID,CHAR_VALUE,LAST_UPDATE_DATE,DISABLE_DATE) values (591333,710326,'01',to_date('09-FEB-06','DD-MON-RR'),to_date('07-NOV-01','DD-MON-RR'));
Insert into BP_ATTRIBUTE_CHARVAL (ATTRIBUTE_ID,PARTNER_ID,CHAR_VALUE,LAST_UPDATE_DATE,DISABLE_DATE) values (591323,710326,'X1',to_date('09-FEB-06','DD-MON-RR'),to_date('07-NOV-01','DD-MON-RR'));
Insert into BP_ATTRIBUTE_CHARVAL (ATTRIBUTE_ID,PARTNER_ID,CHAR_VALUE,LAST_UPDATE_DATE,DISABLE_DATE) values (591334,710326,'BS',to_date('09-FEB-06','DD-MON-RR'),to_date('07-NOV-01','DD-MON-RR'));
REM INSERTING into BP_ATTRIBUTE_CHARVAL_GTT
Insert into BP_ATTRIBUTE_CHARVAL_GTT(ATTRIBUTE_ID,PARTNER_ID,CHAR_VALUE,LAST_UPDATE_DATE,DISABLE_DATE) values (591330,707408,'01',to_date('29-MAR-06','DD-MON-RR'),to_date('07-NOV-01','DD-MON-RR'));
Insert into BP_ATTRIBUTE_CHARVAL_GTT(ATTRIBUTE_ID,PARTNER_ID,CHAR_VALUE,LAST_UPDATE_DATE,DISABLE_DATE) values (591321,707408,'N',to_date('23-JAN-06','DD-MON-RR'),to_date('07-NOV-01','DD-MON-RR'));
Insert into BP_ATTRIBUTE_CHARVAL_GTT(ATTRIBUTE_ID,PARTNER_ID,CHAR_VALUE,LAST_UPDATE_DATE,DISABLE_DATE) values (591331,707408,'00',to_date('23-JAN-06','DD-MON-RR'),to_date('07-NOV-01','DD-MON-RR'));
Insert into BP_ATTRIBUTE_CHARVAL_GTT(ATTRIBUTE_ID,PARTNER_ID,CHAR_VALUE,LAST_UPDATE_DATE,DISABLE_DATE) values (591329,707408,'01',to_date('23-JAN-06','DD-MON-RR'),to_date('07-NOV-01','DD-MON-RR'));
Insert into BP_ATTRIBUTE_CHARVAL_GTT(ATTRIBUTE_ID,PARTNER_ID,CHAR_VALUE,LAST_UPDATE_DATE,DISABLE_DATE) values (591332,707408,'00',to_date('29-MAR-06','DD-MON-RR'),to_date('07-NOV-01','DD-MON-RR'));
Insert into BP_ATTRIBUTE_CHARVAL_GTT(ATTRIBUTE_ID,PARTNER_ID,CHAR_VALUE,LAST_UPDATE_DATE,DISABLE_DATE) values (591324,707408,'2',to_date('29-MAR-06','DD-MON-RR'),to_date('07-NOV-01','DD-MON-RR'));
Insert into BP_ATTRIBUTE_CHARVAL_GTT(ATTRIBUTE_ID,PARTNER_ID,CHAR_VALUE,LAST_UPDATE_DATE,DISABLE_DATE) values (591333,707408,'01',to_date('23-JAN-06','DD-MON-RR'),to_date('07-NOV-01','DD-MON-RR'));
Insert into BP_ATTRIBUTE_CHARVAL_GTT(ATTRIBUTE_ID,PARTNER_ID,CHAR_VALUE,LAST_UPDATE_DATE,DISABLE_DATE) values (591323,707408,'X1',to_date('23-JAN-06','DD-MON-RR'),to_date('07-NOV-01','DD-MON-RR'));
Insert into BP_ATTRIBUTE_CHARVAL_GTT(ATTRIBUTE_ID,PARTNER_ID,CHAR_VALUE,LAST_UPDATE_DATE,DISABLE_DATE) values (591334,707408,'BS',to_date('23-JAN-06','DD-MON-RR'),to_date('07-NOV-01','DD-MON-RR'));
Insert into BP_ATTRIBUTE_CHARVAL_GTT(ATTRIBUTE_ID,PARTNER_ID,CHAR_VALUE,LAST_UPDATE_DATE,DISABLE_DATE) values (876570,707408,'01',to_date('29-MAR-06','DD-MON-RR'),to_date('07-NOV-01','DD-MON-RR'));
Insert into BP_ATTRIBUTE_CHARVAL_GTT (ATTRIBUTE_ID,PARTNER_ID,CHAR_VALUE,LAST_UPDATE_DATE,DISABLE_DATE) values (876568,707408,'1234560003264801',to_date('29-MAR-06','DD-MON-RR'),to_date('07-NOV-01','DD-MON-RR'));
Insert into BP_ATTRIBUTE_CHARVAL_GTT(ATTRIBUTE_ID,PARTNER_ID,CHAR_VALUE,LAST_UPDATE_DATE,DISABLE_DATE) values (876569,707408,'f3a1d996-720e-4e0a-989c-6d4f3e8e629a',to_date('29-MAR-06','DD-MON-RR'),to_date('07-NOV-01','DD-MON-RR'));
Insert into BP_ATTRIBUTE_CHARVAL_GTT(ATTRIBUTE_ID,PARTNER_ID,CHAR_VALUE,LAST_UPDATE_DATE,DISABLE_DATE) values (874948,707408,'20060318000000',to_date('29-MAR-06','DD-MON-RR'),to_date('07-NOV-01','DD-MON-RR'));
select 707408,
decode(g.attribute_id,NULL,c.attribute_id,g.attribute_id) attribute_id,
case
when c.last_update_date is null and g.last_update_date is not null
then
g.char_value
when g.last_update_date is null and c.last_update_date is not null
then
c.char_value
when g.last_update_date >= c.last_update_date
then
g.char_value
else
c.char_value
end char_value,
decode(g.last_update_date,c.last_update_date,g.last_update_date,c.last_update_date) last_update_date,
decode(g.disable_date,c.disable_date,g.disable_date,c.disable_date) disable_date
from bp_attribute_charval_gtt g
full outer join
bp_attribute_charval c
on c.attribute_id = g.attribute_id
where c.partner_id=710326;Hi Guys
When I run the above query I get a problem.
I am expecting to see is a merge of all the attribute_id's and their values.
The query does not appear to be merging the data as intended.
My understanding of the full outer join is that its a combination of left and outer joins,
so the above query is intended to return with the total number of unique attributes
and their appropriate values
a) I have a bug in the Sql
b) This is an oracle bug
c) My understanding is incorrect
Please Help
Message was edited by:
Keith Jamieson (fixed insert statements for gtt )How do you expect a full outer join operation when you have given --
where c.partner_id=710326;According to your supplied data - i don't think your query can perform that full outer join operation because of that filtration. Just remove that last condition and checked it. You will get your desired result - hopefully.
"It's like you want to view the things by closing down your both eyes". Do you think it will pay?
Regards.
Satyaki De. -
Full outer join query giving error
Hi I have written the below query to get the fields below as an out put but am getting the error missing keyword..am not understanding where did i missed..i have done step by step query analysis..but could not find the error.
Please help me in resolving the issue.
Expected output Columns :*
COUNTRY , TRN_TYPE ,SKU ,BIX_Customer ,PERIOD ,CURRENTSTOCK ,STOCK_VALUE ,SALES ,SALES_VALUE ,TARGET
Query :_
select (case when a.country is null then b.country when b.country is null then c.country else a.country end) AS COUNTRY,
(case when a.Sale_Type is null then b.Stk_type when b.stk_type is null then c.Stk_type else a.Sale_Type end) AS TRN_TYPE,
(case when a.sku is null then b.sku when b.sku is null then c.sku else a.sku end) AS SKU,
(case when a.bix_customer is null then b.bix_customer_code when b.bix_customer_code is null then c.bix_customer_code else a.bix_customer end)AS BIX_Customer ,
(case when a.period is null then TO_number(b.period) when b.period is null then TO_NUMBER(c.period) else a.period end) AS PERIOD,
nvl(b.CURRENTSTOCK,0) AS CURRENTSTOCK,
nvl(b.stock_value,0) AS STOCK_VALUE,
nvl(a.sales,0) AS SALES,
nvl(a.SALES_VALUE,0) AS SALES_VALUE,
nvl(c.TARGET_QTY,0) AS TARGET
from
(select UPPER(c.cust_country_name) AS COUNTRY,
DECODE(ds.account_key,7156,'SAMPLE',7157,'BONUS',7485,'SALE') AS Sale_Type,
substr(i.item_code,7) AS SKU,
c.bix_customer_code AS BIX_Customer,
ds.descr as descr ,
ds.period as period,
sum(ds.quantity) AS SALES,
sum(case when ds.local_value is null then ds.euro_value else ds.local_value END) AS SALES_VALUE
FROM distributor_sales ds, customer c, item i
where ds.customer_key=c.customer_key
and ds.item_key= i.item_key
group by ds.period,
ds.account_key,
c.cust_country_name,
substr(i.item_code,7),
c.bix_customer_code,
ds.descr) a
full outer join
(SELECT UPPER(b.cust_country_name) AS COUNTRY,
DECODE(s.stock_type,'SALE','SALE','SALES','SALE','BONUS','BONUS','SAMPLE','SAMPLE') AS Stk_type,
substr(c.item_code,7) AS SKU,
s.descr as descr,
s.period as period,
b.bix_customer_code,
sum(s.CLOSING_STOCK) CURRENTSTOCK,
sum(s.closing_stock*s.cif_price) STOCK_VALUE
FROM STOCK s, customer b, item c
WHERE s.customer_key=b.customer_key
and s.item_key= c.item_key
group by
s.descr,
s.stock_type,
s.period, b.bix_customer_code,b.cust_country_name,substr(c.item_code,7) ) b
full outer join
(SELECT UPPER(cu.cust_country_name) AS COUNTRY,
DECODE(t.description,'SALES TARGET','SALE') AS Stk_type,
substr(it.item_code,7) AS SKU,
t.channel as channel,
t.period as period,
cu.bix_customer_code as bix_customer_code,
sum(t.quantity) TARGET_QTY
FROM sales_target t, customer cu, item it
WHERE t.customer_key=cu.customer_key
and t.item_key= it.item_key
group by
t.channel,
t.description,
t.period, cu.bix_customer_code,cu.cust_country_name,substr(it.item_code,7) ) c
on a.SKU=b.SKU
and a.sku=c.SKU
and b.sku=c.SKU
and a.BIX_Customer=b.bix_customer_code
and a.BIX_Customer=c.bix_customer_code
and b.bix_customer_code=c.bix_customer_code
and a.Sale_Type=b.Stk_type
and a.Sale_Type=c.Stk_type
and b.Stk_type=c.Stk_type
and a.descr=b.descr
and b.descr=c.channel
and a.descr=c.channel
and a.country=b.country
and a.country=c.COUNTRY
and b.country=c.COUNTRY
and a.period=b.period
and a.period=c.period
and b.period=c.period;<tt>Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production</tt>
You must be aware that you must cascade full outer joins
with
t1 as
(select 1 key,1.1 data from dual union all
select 3,1.3 from dual union all
select 6,1.6 from dual union all
select 7,1.7 from dual
t2 as
(select 2 key,2.2 data from dual union all
select 3,2.3 from dual union all
select 4,2.4 from dual union all
select 6,2.6 from dual
t3 as
(select 4 key,3.4 data from dual union all
select 5,3.5 from dual union all
select 6,3.6 from dual union all
select 7,3.7 from dual
select nvl(x.key,t3.key) key,
x.data_1,
x.data_2,
t3.data data_3
from (select nvl(t1.key,t2.key) key,
t1.data data_1,
t2.data data_2
from t1
full outer join
t2
on t1.key = t2.key
) x
full outer join
t3
on t3.key = x.key
order by keyunless you can live with duplicate key rows you cannot avoid whenever all table pairs contain common keys (try the below using data from above)
select coalesce(t1.key,t2.key,t3.key) key,
t1.data data_1,
t2.data data_2,
t3.data data_3
from t1
full outer join
t2
on t1.key = t2.key
full outer join
t3
on t3.key = t1.key
and t3.key = t2.key
order by key
select coalesce(t1.key,t2.key,t3.key) key,
t1.data data_1,
t2.data data_2,
t3.data data_3
from t2
full outer join
t3
on t2.key = t3.key
full outer join
t1
on t1.key = t2.key
and t1.key = t3.key
order by key
select coalesce(t1.key,t2.key,t3.key) key,
t1.data data_1,
t2.data data_2,
t3.data data_3
from t1
full outer join
t3
on t1.key = t3.key
full outer join
t2
on t2.key = t1.key
and t2.key = t3.key
order by keyRegards
Etbin
Edited by: Etbin on 10.4.2013 9:53
If you're after
select *
from (select *
from (select *
from t1
) a
full outer join
(select *
from t2
) b
on t1.key = t2.key
) x
full outer join
t3
on t3.key = x.key
order by keyyou're presently at
select *
from (
(select *
from t1
) a
full outer join
(select *
from t2
) b
on t1.key = t2.key
) x
full outer join
t3
on t3.key = x.key
order by keyORA-00933: SQL command not properly ended -
Union among multiple select queries with full outer join
Hello everyone,
I have 3 different select queries (used FULL Outer Join) which work fine. Now I want to add Union to the results among them and pick the selected columns from each query in the final result. while doing so, I am getting an error as "right parenthesis missing". I am quite sure, it is not the real cause. I guess might be issue with the query structure.
select j.pod, j.hostname, portal.hostname,saasc.hostname,a3s.hostname from -- * from
Select J.Pod,J.Hostname, P.Pod Portal_Pod,P.Hostname Portal_Hostname
From Total_Pod J
full outer join Portal_Tmp P On (J.Pod = P.Pod And J.Hostname = P.Hostname) as portal
Union
Select J.Pod,J.Hostname, s.Pod saasc_Pod,s.Hostname saasc_Hostname
From Total_Pod J
full outer join Saasc_Tmp S On (J.Pod = s.Pod And J.Hostname = s.Hostname) as saasc
Union
Select J.Pod,J.Hostname, a.Pod a3s_Pod,a.Hostname a3s_Hostname
From Total_Pod J
Full Outer Join A3s_Tmp A On (J.Pod = A.Pod And J.Hostname = A.Hostname) as a3s
)p.s: select * from (INNER QUERY); also does not work.
Any help appreciated.
Thanks in advance.With T as
(Select J.Pod,J.Hostname, P.Pod Portal_Pod,P.Hostname Portal_Hostname
From Total_Pod J
full outer join Portal_Tmp P On (J.Pod = P.Pod And J.Hostname = P.Hostname) ),
U as
(Select J.Pod,J.Hostname, s.Pod saasc_Pod,s.Hostname saasc_Hostname
From Total_Pod J
full outer join Saasc_Tmp S On (J.Pod = s.Pod And J.Hostname = s.Hostname) ),
V as
(Select J.Pod,J.Hostname, a.Pod a3s_Pod,a.Hostname a3s_Hostname
From Total_Pod J
Full Outer Join A3s_Tmp A On (J.Pod = A.Pod And J.Hostname = A.Hostname) )
Select T.Pod,T.Hostname,nvl(T.Portal_Hostname,'Not Available') portal,nvl(U.Saasc_Hostname,'Not Available') saasc,NVL(V.A3s_Hostname,'Not Available') a3s From T,U,V
Where T.Pod = U.Pod
And U.Pod = V.Pod
And T.Hostname = U.Hostname
And U.Hostname = V.Hostname
Maybe you are looking for
-
Tree view display along with icons
Hi all Anybody please give me the complete code to display the tree view which takes input from selection screen.I also need to display icons in the tree view.please help its urgent. Thank you. Regards Giri
-
Parameters for calling PCR Direct Launch
Hi, We have a custom webDynpro that lets manager select employees outside of their org unit for transfer into their org unit. Once the employee is selected how do we call the PCR Direct Launch iview with this employee number as a parameter? Is it eve
-
How do I remove invalid develop presets
Hi. I've had Lightroom on my Mac for quite some time. I've gone through periods where I use it, then periods where I don't. In one of those iterations, I somehow got a list of develop presets that are not valid. When I go to the develop section, I
-
New developer resource - Lightroom SDK Cookbook
Hi All, You might have noticed that the overview for this forum has changed recently, and that two new links have been added: Lightroom Developer Center Lightroom Cookbook The first you will no doubt be familiar with as it is the official location fo
-
RBAC Role Group rights across a Forest Trust
Just looking for confirmation here, really. I am trying to give user "Jason Argonaut" in ForestA access to ForestB, as an Org Man & Recipt Man member, through a linked mailbox. It appears that some access is given once the ForestB mailbox is Linked t