Outer join with nested tables
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,
Boris
Hi 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.
Similar Messages
-
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> -
ANSI Standard Join with Nested Table
Does anyone know how to (or whether you actually can) use ansi standard table joins with nested tables.
Non-ansi standard would look something like this
SELECT e.empno
FROM departments d, TABLE(d.employees) e
WHERE d.deptno = 10;
Where d.employees is a nested table.
But if I try ansi-standard I like such:
SELECT e.empno
FROM departments d
JOIN TABLE(d.employees) e
WHERE d.deptno = 10;
I get
ORA-00905: missing keyword
because I have nothing to join it on.
Your help is very much appreciatedBoth replies worked fine.
I think I will go with the NATURAL JOIN as it seems the cleanest option.
Thanks Guru 2748 -
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. -
Please look at this tables and help me how i do get result in "Result tbl" tables ..
try that !
select a.*, case
when a.item_type = 1 then b.inv_date
when a.item_type = 3 then c.deb_date
end as item_date
from receipt_item a
left join invoice b on a.item_id = b.invvi_id and a.item_type = 1
left join Debit c on a.item_id = c.deb_id and a.item_type = 3 -
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?
-
Join columns of outer join with table have no uniqueness cons
Hi! I'm getting noizy error in alert log from time to time:
Join columns of outer join with table <table_name> have no uniqueness constraints
I've collected all the queries (v$sql, all_source) with montioned table, but non of them produces that error if executed.
Any hints how to reproduce this error or where else to search that buggy sql join?
Edited by: user545083 on 25.10.2010 6:21Hi
I think this error is output via an materialized view refresh - check for mviews against the given table which fulfil the issue given in the error text.
Thanks
Paul -
Join two tables to one recordset with nested table?
Hello all!
I want to "de-normalize" two tables into one for presentation reasons. For example:
CREATE TABLE foo(id number)
CREATE TABLE bar(foo_id number, value varchar2(4))
And with some data:
FOO:
1
2
BAR:
1, 'gaz'
1, 'boz'
2, 'blah'
Now I want to create a view that holds the value of the BAR table in a nested table, if possible and efficient enough..
VIEW:
1, nested_table('gaz,'boz')
2, nested_table('blah')
Any clue for creating such a view? I would prefer a view, because this view will be joined with other tables later.
Thanks in advice!Or
SQL> with foo as
2 ( select 1 id from dual union all
3 select 2 id from dual
4 ),
5 bar as
6 (
7 select 1 foo_id, 'gaz' value from dual union all
8 select 1 foo_id, 'boz' value from dual union all
9 select 2 foo_id, 'blah' value from dual
10 )
11 --
12 --
13 select id,
14 cast(multiset((select value from bar where id=foo_id)) as sys.dbms_debug_vc2coll) value
15 from foo
16 /
ID VALUE
1 DBMS_DEBUG_VC2COLL('gaz', 'boz')
2 DBMS_DEBUG_VC2COLL('blah')or from 10g on
SQL> with foo as
2 ( select 1 id from dual union all
3 select 2 id from dual
4 ),
5 bar as
6 (
7 select 1 foo_id, 'gaz' value from dual union all
8 select 1 foo_id, 'boz' value from dual union all
9 select 2 foo_id, 'blah' value from dual
10 )
11 --
12 --
13 select id,
14 cast(collect(value) as sys.dbms_debug_vc2coll) value
15 from foo, bar
16 where id=foo_id
17 group by id
18 /
ID VALUE
1 DBMS_DEBUG_VC2COLL('gaz', 'boz')
2 DBMS_DEBUG_VC2COLL('blah')Edited by: michaels2 on Oct 8, 2008 2:27 PM -
Problem with outer join with filter on join column
Hi,
In physical layer I have one dimension and two facts, and there's an outer join between the facts.
dim_DATE ,
fact_1 ,
fact_2
Joins:
dim_DATE inner join fact_1 on dim_DATE.DATE = fact_1.DATE
fact_1 left outer join fact_2 on fact_1.DATE = fact_2.DATE and fact_1.SOME_ID = fact_2.SOME_ID
When I run a report with a date as a filter, OBIEE executes "optimized" physical SQL:
select fact1.X, fact2.Y
from
Fact_1 left outer join on fact_1.DATE = fact_2.DATE and fact_1.SOME_ID = fact_2.SOME_ID
where Fact_1.DATE = TO_DATE('2009-05-28' , 'YYYY-MM-DD' )
and Fact_2.DATE = TO_DATE('2009-05-28' , 'YYYY-MM-DD')
The filter on Fact_2.DATE effectively replaces outer join with inner.
Is there a way to disable this "optimization", which is actually very good for inner joins, but doesn't allow outer joins?
Thanks in advance,
Alex
Edited by: AM_1 on Aug 11, 2009 8:20 AMIf you want to perform a Fact-based partitioning with OBIEE (two fact with the same dimension), you have to :
* create in your physical layer for each fact table the joins with the dimension
* create in the Business Model layer ONE star schema with ONE logical fact table containing the columns of your two physical fact table
In this way when you choose minimal one column of your fact1 and one column of your fact2, OBIEE will perform two query against each fact table/dimension, join them with an OUTER JOIN and your problem will disappear.
Cheers
Nico -
Outer Join with Where Clause in LTS
HI all,
I have a requirement like this in ANSI SQL:
select p1.product_id, p1.product_name, p2.product_group
from product p1 left outer join product_group p2 on p1.product_id = p2.product_id
and p2.product_group = 'NEW'
In Regular SQL:
select p1.product_id, p1.product_name, p2.product_group
from product p1, product_group p2
WHERE p1.product_id *= p2.product_id and p2.product_group = 'NEW'
In OBIEE, I am using a left outer join between these two in Logical table Source, and also, Gave
p2.product_group = 'NEW' in WHERE clause of LTS.
This doesn't seem to solve purpose.
Do you have any idea how to convert WHERE clause in physical query that OBIEE is generating to something like
product p1 left outer join product_group p2 on p1.product_id = p2.product_id AND p2.product_group = 'NEW'
I am using Version 10.1.3.4.1
Creating an Opaque view would be my last option though.Hello
I have read your post and the responses as well. and I understand that you have issues with the Outer Join with where Clause in LTS.
Try this solution which worked for me (using your example ) -
1. In the Physical Layer created a Complex join between PRODUCT and PRODUCT_GROUP tables and use this join relationship :
PRODUCT.PROD_ID = PRODUCT_GROUP.PROD_ID AND PRODUCT_GROUP.GROUP_NAME = 'MECHANICAL'
2. In the General Tab of PRODUCT table LTS add PRODUCT_GROUP table and select Join Type as Left Outer Join.
3. Check Consistency and make sure there are no errors .
when you run a request you should see the following query generated -
select distinct T26908.PROD_ID as c1,
T26908.PROD_NAME as c2,
T26912.GROUP_NAME as c3
from
PRODUCT T26908 left outer join PRODUCT_GROUP T26912 On T26908.PROD_ID = T26912.PROD_ID and T26912.GROUP_NAME = 'MECHANICAL'
order by c1, c2, c3
Hope this works for you. If it does please mark this response as 'Correct' .
Good Luck. -
Oracle outer join on multiple tables throws error
Hi ,
We are using ansi joins with outer joins on multiple tables in oracle 9i.
Now these queries have to be used in Oracle8i.
Since Oracle8i does not support ansi sql we are replacing the ansi sql queries with the oracle joins.
On trying the same we found that the following query
select *from tab1 a, tab2 b, tab3 c where a.c1 = b.col1(+) and c.c2 = b.col2 (+)
throws the error
ORA-01417: a table may be outer joined to at most one other table.
Is there a way to simulate this query without using the outer joins on multiple tables?
thanksTry writing the query in this form:
select * from
(select t1.col1, t1.col2
from schema.table1 t1, schema.table2 t2
where t1.col1 = t2.col1(+)) t4,
schema.table3 t3 where t4.col2 = t3.col2(+)
In the subquery, you will have to list all the columns you want to see, and you will need to provide unique aliases for any columns with duplicate names. I tested this on 9i, and don't have an 8i system to work with, so I hope this helps. -
Outer join with Filter condition
Hi there,
I need some help with Data Services. I am creating an outer join between two tables and one of them has filter condition but it creates and outerjoin and apply the filter condition to the whole result set.
SELECT "IWFMR13T_VEH_NTK_TMP1"."ACTY_DT" , "IWFMR13T_VEH_NTK_TMP1"."VEH_CL" , "IWFMR13T_VEH_NTK_TMP1"."VEH_NO" , "IWFMR13T_VEH_NTK_TMP1"."SRVC_NO" , "IWFMR13T_VEH_NTK_TMP1"."SRVC_STRT_DT" , "IWFMR13T_VEH_NTK_TMP1"."FR_SRVC_SEQ_NO" , "IWFMR13T_VEH_NTK_TMP1"."TO_SRVC_SEQ_NO" , "IWFMR13T_VEH_NTK_TMP1"."FR_ACTY_TS" , "IWFMR13T_VEH_NTK_TMP1"."TO_ACTY_TS" , "IWFMR13T_VEH_NTK_TMP1"."MINS_ON_TRN" , "IWFMR13T_VEH_NTK_TMP1"."VEH_STA_CD" , "IWFMR13T_VEH_NTK_TMP1"."MAJ_VEH_CD" , "IWFMR13T_VEH_NTK_TMP1"."VEH_DIST_KM" , "IWFMR13T_VEH_NTK_TMP1"."VEH_NET_TN" , "IWFMR13T_VEH_NTK_TMP1"."VEH_GROS_TN" , "IWFMR13T_VEH_NTK_TMP1"."VEH_NTK" , "IWFMR13T_VEH_NTK_TMP1"."VEH_GTK" , "IWFMR13T_VEH_NTK_TMP1"."HLNG_LOCO_MPU" , "IWFMR13T_VEH_NTK_TMP1"."09_HLNG_LOCO_FL" , "IWFMR13T_VEH_NTK_TMP1"."LOCO_MPU" , "IWFMR11T_SGMT_LCNT"."SUM_LOCO_MPU" , "IWFMR13T_VEH_NTK_TMP1"."SRVC_BUS_GRP_CD" , "IWFMR13T_VEH_NTK_TMP1"."SRVC_COAL_MRKR_CD"
FROM "DBO"."IWFMR13T_VEH_NTK_TMP1" "IWFMR13T_VEH_NTK_TMP1"
LEFT OUTER JOIN "DBO"."IWFMR11T_SGMT_LCNT" "IWFMR11T_SGMT_LCNT"
ON ( "IWFMR11T_SGMT_LCNT"."SRVC_NO" = "IWFMR13T_VEH_NTK_TMP1"."SRVC_NO" ) AND( "IWFMR11T_SGMT_LCNT"."SRVC_STRT_DT" = "IWFMR13T_VEH_NTK_TMP1"."SRVC_STRT_DT" ) AND( "IWFMR11T_SGMT_LCNT"."FR_SRVC_SEQ_NO" = "IWFMR13T_VEH_NTK_TMP1"."FR_SRVC_SEQ_NO" ) AND( "IWFMR11T_SGMT_LCNT"."TO_SRVC_SEQ_NO" = "IWFMR13T_VEH_NTK_TMP1"."TO_SRVC_SEQ_NO" )
WHERE ( "IWFMR13T_VEH_NTK_TMP1"."09_HLNG_LOCO_FL" = 'Y')
While, what I need is as under
SELECT "IWFMR13T_VEH_NTK_TMP1"."ACTY_DT" , "IWFMR13T_VEH_NTK_TMP1"."VEH_CL" , "IWFMR13T_VEH_NTK_TMP1"."VEH_NO" , "IWFMR13T_VEH_NTK_TMP1"."SRVC_NO" , "IWFMR13T_VEH_NTK_TMP1"."SRVC_STRT_DT" , "IWFMR13T_VEH_NTK_TMP1"."FR_SRVC_SEQ_NO" , "IWFMR13T_VEH_NTK_TMP1"."TO_SRVC_SEQ_NO" , "IWFMR13T_VEH_NTK_TMP1"."FR_ACTY_TS" , "IWFMR13T_VEH_NTK_TMP1"."TO_ACTY_TS" , "IWFMR13T_VEH_NTK_TMP1"."MINS_ON_TRN" , "IWFMR13T_VEH_NTK_TMP1"."VEH_STA_CD" , "IWFMR13T_VEH_NTK_TMP1"."MAJ_VEH_CD" , "IWFMR13T_VEH_NTK_TMP1"."VEH_DIST_KM" , "IWFMR13T_VEH_NTK_TMP1"."VEH_NET_TN" , "IWFMR13T_VEH_NTK_TMP1"."VEH_GROS_TN" , "IWFMR13T_VEH_NTK_TMP1"."VEH_NTK" , "IWFMR13T_VEH_NTK_TMP1"."VEH_GTK" , "IWFMR13T_VEH_NTK_TMP1"."HLNG_LOCO_MPU" , "IWFMR13T_VEH_NTK_TMP1"."09_HLNG_LOCO_FL" , "IWFMR13T_VEH_NTK_TMP1"."LOCO_MPU" , "IWFMR11T_SGMT_LCNT"."SUM_LOCO_MPU" , "IWFMR13T_VEH_NTK_TMP1"."SRVC_BUS_GRP_CD" , "IWFMR13T_VEH_NTK_TMP1"."SRVC_COAL_MRKR_CD"
FROM "DBO"."IWFMR13T_VEH_NTK_TMP1" "IWFMR13T_VEH_NTK_TMP1"
LEFT OUTER JOIN "DBO"."IWFMR11T_SGMT_LCNT" "IWFMR11T_SGMT_LCNT"
ON ( "IWFMR11T_SGMT_LCNT"."SRVC_NO" = "IWFMR13T_VEH_NTK_TMP1"."SRVC_NO" ) AND( "IWFMR11T_SGMT_LCNT"."SRVC_STRT_DT" = "IWFMR13T_VEH_NTK_TMP1"."SRVC_STRT_DT" ) AND( "IWFMR11T_SGMT_LCNT"."FR_SRVC_SEQ_NO" = "IWFMR13T_VEH_NTK_TMP1"."FR_SRVC_SEQ_NO" ) AND( "IWFMR11T_SGMT_LCNT"."TO_SRVC_SEQ_NO" = "IWFMR13T_VEH_NTK_TMP1"."TO_SRVC_SEQ_NO" ) AND ( "IWFMR13T_VEH_NTK_TMP1"."09_HLNG_LOCO_FL" = 'Y')
Please let me know, how to fix this issue. If you have come across such issue before. If need be I can send you the ATL file for this data flow.
BTW, I am using Data Services XI 3.2 (12.2.0.0) and the database is SQL 2005, both on Windows Platform.
Thanks & regards,
Doshi BhaveshHi,
Use two query transforms;
First will only connect to IWFMR13T_VEH_NTK_TMP1 and use it to apply filter "IWFMR13T_VEH_NTK_TMP1"."09_HLNG_LOCO_FL" = 'Y'
In second query transform perform outer join on IWFMR11T_SGMT_LCNT and output of first query.
This should give required result.
If you are using single query transform join will be performed at DB level and if you use custom sql in query transform it will not have increased load on DB. I will recommend to use custom sql to get good performance.
Sachin -
Outer join With a constant value
Hi all,
In one of query i have found out that the outer join with a constant value like
to_currency(+)='USD'
to_currency is a column name in a table.can any one please explain this outer join condtn.
Thanks in advance
SenthilHallo,
if you write var (+) = constant
var can be equal constant, and also can be null
Compare these 2 queries
select e.* from scott.emp e, scott.dept d
where e.deptno = d.deptno(+)
and d.deptno(+) = 10EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 SMITH CLERK 7902 17-Dez-1980 800 20
7499 ALLEN SALESMAN 7698 20-Feb-1981 1600 300 30
7521 WARD SALESMAN 7698 22-Feb-1981 1250 500 30
7566 JONES MANAGER 7839 2-Apr-1981 2975 20
7654 MARTIN SALESMAN 7698 28-Sep-1981 1250 1400 30
7698 BLAKE MANAGER 7839 1-Mai-1981 2850 30
7782 CLARK MANAGER 7839 9-Jun-1981 2450 10
7788 SCOTT ANALYST 7566 19-Apr-1987 3000 20
7839 KING PRESIDENT 17-Nov-1981 5000 10
7844 TURNER SALESMAN 7698 8-Sep-1981 1500 0 30
7876 ADAMS CLERK 7788 23-Mai-1987 1100 20
7900 JAMES CLERK 7698 3-Dez-1981 950 30
7902 FORD ANALYST 7566 3-Dez-1981 3000 20
7934 MILLER CLERK 7782 23-Jan-1982 1300 10
select e.* from scott.emp e, scott.dept d
where e.deptno = d.deptno(+)
and d.deptno = 10 EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7782 CLARK MANAGER 7839 9-Jun-1981 2450 10
7839 KING PRESIDENT 17-Nov-1981 5000 10
7934 MILLER CLERK 7782 23-Jan-1982 1300 10
As you can see, this (+) is very important
Regards
Dmytro -
I have a very complicated query to construct that requires the use of 'AND', 'OR', and Outer Joins. Oracle's 9i documentation says you can't use an outer join with an 'OR'.
Can you suggest how I may return the correct records under the following conditions. There are 3 tables to join. Table A, Table B, and Table C. Tables A & B join with an = to common fields. The problem is with Table C.
The way the application was designed, it has to track a parent and child relationship. As such, the field to relate may exist in 1 of 2 fields. Let's see if I can draw it out for you.
Table A - Record 1
(ID = 1)
Table B - Record 1
(ID =1 [this relates to Table A.ID]
PID = 12345
CID = 67899
Site = A)
Table C - Record 1
(PID = 12345 [this relates to Table B.PID]
CID = 67899
Site = A)
Table C - Record 2
(PID = 67899 [This relates to Table B.CID]
CID = 12345
Site = A)
Now, I need to relate Table A to Table B where A.ID = B.ID AND
((B.PID = C.PID AND B.CID = C.CID)
OR
(B.CID = C.PID AND B.PID = C.CID))
AND
B.SITE = C.SITE
There may or may NOT be related records in Table C. That's the problem. This is where I need the outer join to get the all the records of the 1st two joins and only those that apply from the last join.
Your help will be greatly appreciated.I'd create two queries, a join from b to c in each of those manners and then UNION ALL the results together.
drop table junk_a;
create table junk_a (
id number );
drop table junk_b;
create table junk_b (
id number,
pid number,
cid number,
site varchar2(80) );
drop table junk_c;
create table junk_c (
pid number,
cid number,
site varchar2(80) );
insert into junk_a values (1);
insert into junk_b values (1, 12345, 67899, 'A');
insert into junk_c values (12345, 67899, 'A');
insert into junk_c values (67899, 12345, 'A');
commit;
SELECT b.*,
c.site AS site_c
FROM junk_b b,
junk_c c
WHERE c.pid(+) = b.pid
AND c.cid(+) = b.cid
UNION ALL
SELECT b.*,
c.site AS site_c
FROM junk_b b,
junk_c c
WHERE c.cid(+) = b.pid
AND c.pid(+) = b.cid;
SELECT a.id,
bc.pid,
bc.cid,
bc.site,
bc.site_c
FROM junk_a a,
SELECT b.*,
c.site AS site_c
FROM junk_b b,
junk_c c
WHERE c.pid(+) = b.pid
AND c.cid(+) = b.cid
UNION ALL
SELECT b.*,
c.site AS site_c
FROM junk_b b,
junk_c c
WHERE c.cid(+) = b.pid
AND c.pid(+) = b.cid
) bc
WHERE bc.id(+) = a.id; -
I have written the below query, our requirement is, Some employees have "Transport Allowance" but not "Project Allowance". For this, I tried to use OUTER JOIN with this query. But this query takes long time and failed. The following query works fine if the employee has both "Transport Allowance" and "Project Allowance" (without outer join) Now, I also need to retrieve the employees who have "Transport Allowance" but not "Project Allowance". How can I retrieve it?
SELECT DISTINCT papf.employee_number
, peev.screen_entry_value Transport_Allowance
,peev1.screen_entry_value Project_Allowance
FROM apps.per_all_people_f papf
,apps.per_all_assignments_f paaf
,apps.pay_element_types_x petf
,apps.pay_element_types_x petf1
,apps.pay_element_types_x petf2
,apps.pay_element_entries_f peef
,apps.pay_element_entries_f peef1
,apps.pay_element_entries_f peef2
,apps.pay_element_entry_values_x peev
,apps.pay_element_entry_values_x peev1
,apps.pay_element_entry_values_x peev2
,apps.pay_input_values_x pivf
,apps.pay_input_values_x pivf1
,apps.pay_input_values_x pivf2
WHERE
papf.person_id = paaf.person_id
AND paaf.assignment_id = peef.assignment_id
AND paaf.assignment_id = peef1.assignment_id
AND paaf.business_group_id = papf.business_group_id
--Transport Allowance
AND peef.element_entry_id = peev.element_entry_id
AND petf.element_Name = 'Transport Allowance'
AND pivf.element_type_id =petf.element_type_id
AND pivf.name = 'Allowance'
AND peev.input_value_id= pivf.input_value_id
--Project Allowance
AND peef1.element_entry_id = peev1.element_entry_id
AND petf1.element_Name = "Project Allowance'
AND pivf1.element_type_id = petf1.element_type_id
AND pivf1.name = 'Allowance'
AND peev1.input_value_id = pivf1.input_value_id
AND (SYSDATE BETWEEN peev.effective_start_date AND peev.effective_end_date)
AND (SYSDATE BETWEEN peev1.effective_start_date AND peev1.effective_end_date)
AND (SYSDATE BETWEEN papf.effective_start_date AND papf.effective_end_date)
ORDER BY papf.employee_number
Thanks in advance.I am using sames tables with alias to retrieve the columns values from the same table.
Here is my query.
SELECT DISTINCT papf.employee_number
, peev.screen_entry_value Transport_Allowance
,peev1.screen_entry_value Project_Allowance
FROM apps.per_all_people_f papf
,apps.per_all_assignments_f paaf
,apps.pay_element_types_x petf
,apps.pay_element_types_x petf1
,apps.pay_element_entries_f peef
,apps.pay_element_entries_f peef1
,apps.pay_element_entry_values_x peev
,apps.pay_element_entry_values_x peev1
,apps.pay_input_values_x pivf
,apps.pay_input_values_x pivf1
WHERE
papf.person_id = paaf.person_id
AND paaf.assignment_id = peef.assignment_id
AND paaf.assignment_id = peef1.assignment_id
AND paaf.business_group_id = papf.business_group_id
--Transport Allowance
AND peef.element_entry_id = peev.element_entry_id
AND petf.element_Name = 'Transport Allowance'
AND pivf.element_type_id =petf.element_type_id
AND pivf.name = 'Allowance'
AND peev.input_value_id= pivf.input_value_id
--Project Allowance
AND peef1.element_entry_id = peev1.element_entry_id
AND petf1.element_Name = "Project Allowance'
AND pivf1.element_type_id = petf1.element_type_id
AND pivf1.name = 'Allowance'
AND peev1.input_value_id = pivf1.input_value_id
AND (SYSDATE BETWEEN peev.effective_start_date AND peev.effective_end_date)
AND (SYSDATE BETWEEN peev1.effective_start_date AND peev1.effective_end_date)
AND (SYSDATE BETWEEN papf.effective_start_date AND papf.effective_end_date)
ORDER BY papf.employee_number
Thanks in advance.
Maybe you are looking for
-
Export PDF Form to XML through VBScript
Hi, I was wondering if there is a way to automate the export of an Adobe PDF Form to XML, either using the Adobe SDK/AcroExch.App or the PDF Test Toolkit. I'm wanting to perform this action via a QuickTest Pro Script and thought there might be a func
-
Test conn. SAPOSS error when opening an RFC connection SNC processing fail
Dear all, I configured a Saprouter in DMZ with SNC connection type to establish connection from my company to SAP and vice-versa. Also I accept connection from external company to our SAP systems. During the test in SM59 SAPOSS connection I receiv
-
VLOOKUP over multiple sheets is NOT working?
I have ported a working Excel sheet into the iOS version on numbers and for what ever reason, the formulas are not working. I have cleared all the cell data and marked with the appropriate field type e.g. number/text. The idea is that on SHEET A the
-
ho comprato un iphone 4 in italia e ora sono in cina per lavoro, e le sim cinesi non funziona sul mio iphone e mi han detto che ho la parte telefonica bloccato da un operatore italiano, come posso sapere qual'è?
-
Si j'utilise l'interface "Measurement & automation" je communique correctement avec le système branché à la carte . Si je démarre ensuite mon programme en C++, je lis correctement les entrées, et écrit correctement sur les sorties. Par contre si je