Using Left Outer Join with reference
I have three tables.Table 1: BOOK_DETAILS
Fields: BOOK_ID, BOOK_NAME
Table 2: BOOK_ISSUE_RECORD
Fields: BOOK_ID, USER_NAME
Table 3: BOOK_AUTHOR
Fields: BOOK_ID, AUTHOR_NAME
I must link table 1 and table 2 with a left outer join, because even if the book is not the questions to anyone, his name should come.
I have once again display the name of the author of books for each book.
I am able to create a query with the left outer join between table 1 and table 2. However, I am not able to give a reference to Table 3.
Can someone help me with this please.
Concerning
Hawker
select d.book_name,
a.book_author,
i.user_name
from book_details d
join
book_author a
on (d.book_id = a.book_id)
left join
book_issue_recors i
on (d.book_id = i.book_id)
/
SY.
Tags: Database
Similar Questions
-
Dear elders,
Firstly, sorry if my question is considered to be 'very novice' but I have this problem of confusion.
Can I use the left outer join with summary?
For example:
Work table
Table No.JobCode JobGroupCode 111A 1100 112B 1100 113C 1100 121A 1200 333F 3300
Activity tableJobGroupCode ParentCode 1100 1000 1200 1000 1300 1000 3300 3000
I want to choose with this resultJobcode Mandays 111A 5 112B 7 113C 3
All I did was:Job.JobCode Job.JobGroupCode JobGroup.Parentcode Mandays 111A 1100 1000 5 112B 1100 1000 7 113C 1100 1000 3 121A 1200 1000 0 333F 3300 3000 0
and I got was only jobcode activity table, not exactly what I want to get all the work table jobcode. Could you please tell me, where I was wrong?select j.jobcode, j.jobgroupcode, jg.parentcode, sum(a.mandays) from job j inner join jobgroup jg on j.jobgroupcode = jg.jobgroupcode left join activity a on j.jobcode = a.jobcode group by j.jobcode, j.jobgroupcode, jg.parentcode
result
Thank you very much.Job.JobCode Job.JobGroupCode JobGroup.Parentcode Mandays 111A 1100 1000 5 112B 1100 1000 7 113C 1100 1000 3
Published by: user11197113 on May 25, 2009 03:31
Published by: user11197113 on May 25, 2009 03:32Hello (and welcome!).
Edit
OK, try this:
select j.jobcode, j.jobgroupcode, jg.parentcode, NVL(sum(a.mandays),0) from job j inner join jobgroup jg on j.jobgroupcode = jg.jobgroupcode left join activity a on j.jobcode = a.jobcode group by j.jobcode, j.jobgroupcode, jg.parentcode
That will give you this:
JOBC JOBG PARE SUM(A.MANDAYS) ---- ---- ---- -------------- 111A 1100 1000 5 112B 1100 1000 7 113C 1100 1000 3 121A 1200 1000 0 333F 3300 3000 0
These are real results of your test data.
-
Why left outer join with a table gives me more lines?
Hi gurus,
I can see "view_a" and a table 'table_a '.
view_a a county of 100 lines. Now, when I left outer join that discovers with a 'table_a', I expect all 100 lines.
However, I'm more than 100 lines. Is it still possible?
Also even to analyze these situations, how can I move forward?
Because it is very high volumn of sight and takes longer to run.
Select count (*) view_a, view_b
where view_a.col1 = view_b.col1 (+)
and view_a.col2 = view_b.col2 (+);
Thank you
I can see "view_a" and a table 'table_a '.
view_a a county of 100 lines. Now, when I left outer join that discovers with a 'table_a', I expect all 100 lines.
However, I'm more than 100 lines. Is it still possible?
Also even to analyze these situations, how can I move forward?
Because it is very high volumn of sight and takes longer to run.
Select count (*) view_a, view_b
where view_a.col1 = view_b.col1 (+)
and view_a.col2 = view_b.col2 (+);
Which is not necessarily related to the use of an outer join.
Just join of two tables in general will give you more rows of one table has.
Scott DEPT table contains ONE row for deptno = 10
The EMP table has THREE rows of deptno = 10
The number of rows you plan if you join two tables using an equi-join?
Three - what is MORE lines the DEPT table has for deptno = 10
Select * from Department where deptno = 10
DEPTNO, DNAME, LOC
10, ACCOUNTING, NEW YORKSelect * from emp where deptno = 10
MGR, EMPLOYMENT ENAME, EMPNO, HIREDATE, SAL, COMM, DEPTNO
7782, CLARK, MANAGER, 7839, 6/9/1981,2450, 10
7839, KING, PRESIDENT, 17 NOVEMBER 00, 10
7934, MILLER, CLERK, 7782, 23 JANUARY 00: 10Select dept.*, emp.*
Department, emp
where dept.deptno = 10
and dept.deptno = emp.deptnoDEPTNO, DNAME, LOC, EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO_1
10, ACCOUNTING, NEW YORK, 7782, CLARK, MANAGER, 7839, 6/9/1981,2450, 10
10, ACCOUNTING, NEW YORK, 7839, KING, PRESIDENT, 17 NOVEMBER 00, 10
10, ACCOUNTING, NEW YORK, 7934, MILLER, CLERK, 7782, 23 JANUARY 00: 10So if these are the lines ONLY in the table EMP and DEPT the query would give you THREE lines despite the DEPT table only ONE line.
No do you expect? You get ALL the child rows that belong to the parent company. Otherwise, how could it possibly work?
The OUTER join includes lines where the parent row exists but there is NO child line as others have shown.
Outer joins
Outer join extends the result of a simple join. Outer join returns all rows that satisfy the join condition and also returns some or all rows in a table for which no line of the other meet the join condition.
Get more lines to exist in one of the paintings is a basic necessity. It usually has NOTHING to with the question of whether you have an outside to join or not.
See the section on the JOINTS in the Oracle documentation
http://docs.Oracle.com/CD/B28359_01/server.111/b28286/queries006.htm
-
Oracle: Use LEFT OUTER JOIN, but convert the data to an external list
Hello, all,.
I know it can be done; I just don't remember how I got it done, oh there are so many years.
Assumes that the tables exist for groups and individuals. People can belong to several groups.
SELECT g.groupName, p.lastName || ', ' || p.firstName as fullName FROM groups g LEFT OUTER JOIN groupPersonAssociation gpa ON gpa.groupID = g.groupID LEFT OUTER JOIN person p ON p.personID = gpa.personID ORDER BY g.groupName, fullName
This gives us:
Group One Alpha, Daniel Group One Bravo, Charles Group One Charlie, Chuck Group Two Beta, Alpha Group Two Delta, Bonnie Group Three Echo, Bunny Group Three Golf, Samuel Group Three November, Stan
How word the SQL to get the data as:
Group One Alpha, Daniel | Bravo, Charles | Charlie, Chuck Group Two Beta, Alpha | Delta, Bonnie Group Three Echo, Bunny | Golf, Samuel | November, Stan
V/r,
^_^
I finally thought to it. I was using incorrect keywords on Google.
SELECT g.groupName, LISTAGG(p.lastName || ', ' || p.firstName,' | ') WITHIN GROUP (ORDER BY g.groupName) "fullName" FROM groups g LEFT OUTER JOIN groupPersonAssociation gpa ON ggpa.groupID = g.groupID LEFT OUTER JOIN person p ON p.personID = gpa.personID GROUP BY g.groupName ORDER BY g.groupName, fullName
Just in case someone else is going through this same desire.
HTH,
^_^
-
Problem format (LEFT OUTER JOIN)?
THE addresses of Mutiple of return as a single record + current addresses
>
Hi all
I have to back student addresses home and dormitory under a single registration.
He had to go something like this:
In this format the desired:LAST_NAME FIRST_NAME ADDY_TYPE ADDRESS ZIP Smith John HOME 123 Awesome St 10003 Smith John DORM Oak Quad 10013
You also need to get their last addresses by date.LAST_NAME FIRST_NAME ADDY_TYPE ADDRESS ZIP ADDY_TYPE ADDRESS ZIP Smith John HOME 123 Awesome St 10003 DORM Oak Quad 10013
The database hold records of all students have places moving from dorm to dorm
and some permanent residence ("HOME") has changed as well.
To return only a DORM address and only a HOME address
for each student.
I'm looking at possibly a function BOX to put on a line/record and RANK BY() or DENSE_RANK to determine the last addresses.
Hope I'm making some sense and as always very grateful for any help. Thank you.
>
The correct code provided by Frank Kulash here:
I need to add a 'NATION' field, located on another table for the addresses of welcome for foreign students.WITH got_rnum AS ( SELECT last_name , first_name , addy_type , address , zip , ROW_NUMBER () OVER ( PARTITION BY last_name , first_name , addy_type ORDER BY addy_date DESC NULLS LAST ) AS rnum FROM table_x -- WHERE ... -- Any filtering goes here ) SELECT last_name , first_name , MIN (CASE WHEN addy_type = 'HOME' THEN address END) AS home_address , MIN (CASE WHEN addy_type = 'HOME' THEN zip END) AS home_zip , MIN (CASE WHEN addy_type = 'DORM' THEN address END) AS dorm_address , MIN (CASE WHEN addy_type = 'DORM' THEN zip END) AS dorm_zip FROM got_rnum WHERE rnum = 1 GROUP BY last_name , first_name ;
I made a LEFT OUTER JOIN with the table of the NATION and the release came out like this:
My desired output would be like this:LAST_NAME FIRST_NAME ADDY_TYPE ADDRESS ZIP NATION ADDY_TYPE ADDRESS ZIP Smith John HOME Rue Henry M1V 4F4 CANADA null null null Smith John null null null null DORM Oak Quad 10013
Maybe it's something I'm not right. What is the way I'm joining tables?LAST_NAME FIRST_NAME ADDY_TYPE ADDRESS ZIP NATION ADDY_TYPE ADDRESS ZIP Smith John HOME Rue Henry M1V 4F4 CANADA DORM Oak Quad 10013
As always very grateful for your contributions. Thank you.Give a glance to your group by, you group on the nation, but it has two values (NULL and CANADA). Try this way:
WITH got_rnum AS ( SELECT STUINFO_id , STUINFO_last_name , STUINFO_first_name , ADDRESSLIST_atyp_code , ADDRESSLIST_street_line1 , ADDRESSLIST_street_line2 , ADDRESSLIST_city , ADDRESSLIST_stat_code , ADDRESSLIST_zip , ADDRESSLIST_natn_code , NATION_nation , ROW_NUMBER () OVER ( PARTITION BY STUINFO_last_name , STUINFO_first_name , ADDRESSLIST_atyp_code ORDER BY ADDRESSLIST_from_date DESC NULLS LAST ) AS rnum FROM STUINFO JOIN CLASSROSTER ON STUINFO_pidm = CLASSROSTER_pidm JOIN ADDRESSLIST ON ADDRESSLIST_pidm = STUINFO_pidm LEFT OUTER JOIN NATION ON ADDRESSLIST_NATN_CODE =NATION_CODE -- The WHERE part determines if the student is currently enrolled in a class -- ADDRESSLIST_to_date is the last date the student will be living in that residence WHERE ADDRESSLIST_atyp_code IN ('PR', 'CA') and STUINFO_change_ind IS NULL and STUINFO_last_name !='Registrar' and CLASSROSTER_term_code='200909' and CLASSROSTER_PTRM_CODE IN ('D', 'D1', 'D2') and CLASSROSTER_CAMP_CODE='1' and (ADDRESSLIST_to_date is NULL OR ADDRESSLIST_TO_DATE > SYSDATE) ) SELECT STUINFO_id , STUINFO_last_name , STUINFO_first_name , MIN (CASE WHEN ADDRESSLIST_atyp_code = 'PR' THEN ADDRESSLIST_STREET_LINE1 END) AS PR_ADDRESSLIST_STREET_LINE1 , MIN (CASE WHEN ADDRESSLIST_atyp_code = 'PR' THEN ADDRESSLIST_STREET_LINE2 END) AS PR_ADDRESSLIST_STREET_LINE2 , MIN (CASE WHEN ADDRESSLIST_atyp_code = 'PR' THEN ADDRESSLIST_city END) AS PR_ADDRESSLIST_city , MIN (CASE WHEN ADDRESSLIST_atyp_code = 'PR' THEN ADDRESSLIST_stat_code END) AS PR_ADDRESSLIST_stat_code , MIN (CASE WHEN ADDRESSLIST_atyp_code = 'PR' THEN ADDRESSLIST_zip END) AS PR_ADDRESSLIST_zip , MIN (CASE WHEN ADDRESSLIST_natn_code IS NULL THEN ADDRESSLIST_natn_code END) AS PR_ADDRESSLIST_natn_code , MIN(NATION_nation) NATION_nation , MIN (CASE WHEN ADDRESSLIST_atyp_code = 'CA' THEN ADDRESSLIST_STREET_LINE1 END) AS CA_ADDRESSLIST_STREET_LINE1 , MIN (CASE WHEN ADDRESSLIST_atyp_code = 'CA' THEN ADDRESSLIST_STREET_LINE2 END) AS CA_ADDRESSLIST_STREET_LINE2 , MIN (CASE WHEN ADDRESSLIST_atyp_code = 'CA' THEN ADDRESSLIST_city END) AS CA_ADDRESSLIST_city , MIN (CASE WHEN ADDRESSLIST_atyp_code = 'CA' THEN ADDRESSLIST_stat_code END) AS CA_ADDRESSLIST_stat_code , MIN (CASE WHEN ADDRESSLIST_atyp_code = 'CA' THEN ADDRESSLIST_zip END) AS CA_ADDRESSLIST_zip FROM got_rnum WHERE rnum = 1 GROUP BY STUINFO_last_name , STUINFO_first_name , STUINFO_id ORDER BY STUINFO_last_name;
Max
-
Problem with XMLTABLE and LEFT OUTER JOIN
Hi all.
I have a problem with XMLTABLE and LEFT OUTER JOIN, in 11g it returns the correct result, but in 10g it doesn't, it is illustrated as a INNER JOIN.
This is all nice, now the problem:SELECT * FROM v$version; Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production PL/SQL Release 11.2.0.1.0 - Production "CORE 11.2.0.1.0 Production" TNS for Linux: Version 11.2.0.1.0 - Production NLSRTL Version 11.2.0.1.0 - Production --test for 11g CREATE TABLE XML_TEST( ID NUMBER(2,0), XML XMLTYPE ); INSERT INTO XML_TEST VALUES ( 1, XMLTYPE (' <msg> <data> <fields> <id>g1</id> <dat>data1</dat> </fields> </data> </msg> ') ); INSERT INTO XML_TEST VALUES ( 2, XMLTYPE (' <msg> <data> <fields> <id>g2</id> <dat>data2</dat> </fields> </data> </msg> ') ); INSERT INTO XML_TEST VALUES ( 3, XMLTYPE (' <msg> <data> <fields> <id>g3</id> <dat>data3</dat> </fields> <fields> <id>g4</id> <dat>data4</dat> </fields> <fields> <dat>data5</dat> </fields> </data> </msg> ') ); SELECT t.id, x.dat, y.seqno, y.id_real FROM xml_test t, XMLTABLE ( '/msg/data/fields' passing t.xml columns dat VARCHAR2(10) path 'dat', id XMLTYPE path 'id' )x LEFT OUTER JOIN XMLTABLE ( 'id' passing x.id columns seqno FOR ORDINALITY, id_real VARCHAR2(30) PATH '.' )y ON 1=1 ; ID DAT SEQNO ID_REAL -- ----- ----- ------- 1 data1 1 g1 2 data2 1 g2 3 data3 1 g3 3 data4 1 g4 3 data5
As you can see in 10g that I don't have the last row, it seems that Oracle 10 g does not recognize the LEFT OUTER JOIN.Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bi PL/SQL Release 10.2.0.1.0 - Production "CORE 10.2.0.1.0 Production" TNS for HPUX: Version 10.2.0.1.0 - Production NLSRTL Version 10.2.0.1.0 - Production --exactly the same environment as 11g (tables and rows) SELECT t.id, x.dat, y.seqno, y.id_real FROM xml_test t, XMLTABLE ( '/msg/data/fields' passing t.xml columns dat VARCHAR2(10) path 'dat', id XMLTYPE path 'id' )x LEFT OUTER JOIN XMLTABLE ( 'id' passing x.id columns seqno FOR ORDINALITY, id_real VARCHAR2(30) PATH '.' )y ON 1=1 ; ID DAT SEQNO ID_REAL -- ----- ----- ------- 1 data1 1 g1 2 data2 1 g2 3 data3 1 g3 3 data4 1 g4
Is this a bug?, Metalink says that sometimes we can have an ORA-0600, but in this case there is no error results returned, just incorrect.
Help, please.
Kind regards.What about try the original Oracle method for outer joins? Using (+) without the extra space
XMLTABLE(...COLUMNS ... id XMLTYPE PATH ... ) x, XMLTABLE(... PASSING x.id ...) (+) y
-
using (+) or left outer join
Dear Expert;
I've been playing by using the two symbol... and realized that they do the same thing... Is it true...? or am I wrong.
Thank you.Hello
user13328581 wrote:
Dear Expert;I've been playing by using the two symbol... and realized that they do the same thing... Is it true...? or am I wrong.
They all have two outer joins. The + rating was the original way to do it in Oracle. LEFT, RIGHT, and FULL OUTER JOIN introduced in Oracle 9, but the old way is still supported.
There are some situations (such as an outer join complete and outer-join a table to two different tables) that are better with the ANSI syntax (it's LEFT OUTER JOIN). It is possible to get the same results using +, but it must be combersome and/or inefficient workarounds. I suggest that you use always LEFT OUTER JOIN (or FULL OUTER JOIN, or, on occasions RIGHT OUTER JOIN). I think that you will find it easier and less error-prone.
-
Hello
I am in charge of the migration of a SQL Server 2000 database to Oracle 11 g, under what I also migrate some predefined queries, that my client has. However I can't seem to get the syntax right and it keeps failing. Could you please help me? Thank you.
Query:
The fields are correct, but I get not found when expected in FROM clause.SELECT *,(select r.recsolins from gx.repara r where r.percod=c.percod and r.concod=c.concod and r.rectpo='I' and r.recsts='F' and r.grppercod=10 and r.recnro=(select max(t.recnro) from gx.repara t where t.percod=c.percod and t.concod=c.concod and t.rectpo='I' andt.recsts='F' ) ) as NROID FROM gx.CONABO c, gx.abonad a LEFT OUTER JOIN gx.CALLES y ON y.dptocod=10 and y.ciucod=524 and y.CALCOD=A.AboCalEsq1, LEFT OUTER JOIN gx.CALLES Z ON z.dptocod=10 and z.ciucod=524 and z.CALCOD=A.AboCalEsq2 ,gx.calles x WHERE c.PERCOD in (10,60) and CONSTSHAB in ('C','D','P') and a.percod=c.percod and a.abocod=c.abocod and x.dptocod=10 and x.ciucod=524 and x.calcod=abocal order by c.percod,c.concod;
Published by: n on June 5, 2012 13:47
-
Get the error invalid identifier in the left outer join
I wrote a query and get the invalid identifier error during execution:
the exact error is: ORA-00904: "D". "" ACCT_NO ": invalid identifier
This query is not able to access the parent table alias in the subquery of the left outer join.
This is the query:
SELECT D.PROD_DESC_TX, BASE. ASSET_NUM, BASE. PROD_ID, BASE.NAME
OF TABLE1 D
LEFT OUTER JOIN
(
SELECT ASSET_NUM, PROD_ID, B.SID
FROM TABLE2 E
JOIN IN-HOUSE TABLE3 HAS IT E.PROD_ID = A.ROW_ID
JOIN INTERNAL TABLE 4 C ON A.PAR_PROD_INT_ID = C.ROW_ID
INTERNAL TABLE5 JOIN B ON C.ROW_ID = B.PAR_ROW_ID
AND B.TYPE = 'VALUE '.
AND B.NAME = 'VALUE '.
WHERE E.ASSET_NUM = ((CASE WHEN LTRIM (RTRIM (D.BANK_NO)) = '021 ' THEN '021' ELSE ' 020' END) |) LTRIM (RTRIM (D.APPL_CD)). LTRIM (RTRIM (D.ACCT_NO)))
) BASE ON ((CASE WHEN LTRIM (RTRIM (D.BANK_NO)) = '021 ' THEN '021' ELSE ' 020' END) |) LTRIM (RTRIM (D.APPL_CD)). LTRIM (RTRIM (D.ACCT_NO))) = BASE. ASSET_NUM
WHERE D.BANK_NO = 'VALUE '.
AND D.APPL_CD = 'VALUE '.
AND D.ACCT_NO = 'VALUE '.
Edited by: user648525 13 Sep, 2011 01:21I can easily look at your request at this time (using my iPhone on a train).
But trying out this line in the WHERE (the one with the invalid reference) clause in the main query.
Who is... in the view of inline, use only the logic of the join (the clauses).
Overflow the filtering logic (WHERE clause) to the main request. You may need to select some additional inline view columns to make these references work.
-
Hi all
I use under version
Connected to Oracle Database 11g Express Edition Release 11.2.0.2.0
SQL > SELECT E.ENAME,.
2 D.DEPTNO,
3 D.LOC
4. TO EMP E,.
DEPT 5 D
6. WHERE = E.DEPTNO D.DEPTNO (+);
ENAME, DEPTNO LOC
---------- ------ -------------
DALLAS SMITH 20
ALLEN 30 CHICAGO
WARD 30 CHICAGO
20 DALLAS JONES
MARTIN 30 CHICAGO
BLAKE 30 CHICAGO
CLARK 10 NEW YORK
SCOTT 20 DALLAS
THE 10 NEW YORK KING
TURNER 30 CHICAGO
20 DALLAS ADAMS
JAMES 30 CHICAGO
FORD 20 DALLAS
MILLER 10 NEW YORK
40 BOSTON
15 selected lines
-----------------------------------------------------------------------------------------------------------------------------
SQL > SELECT E.ENAME,.
2 D.DEPTNO,
3 D.LOC
4. TO EMP E
5 LEFT OUTER JOIN
D 6 DEPT
7. THE E.DEPTNO = D.DEPTNO;
ENAME, DEPTNO LOC
---------- ------ -------------
MILLER 10 NEW YORK
THE 10 NEW YORK KING
CLARK 10 NEW YORK
FORD 20 DALLAS
20 DALLAS ADAMS
SCOTT 20 DALLAS
20 DALLAS JONES
DALLAS SMITH 20
JAMES 30 CHICAGO
TURNER 30 CHICAGO
BLAKE 30 CHICAGO
MARTIN 30 CHICAGO
WARD 30 CHICAGO
ALLEN 30 CHICAGO
14 selected lines
My doubt is both are same query is the same, is in ansi format and is in the format of the Oracle,.
but the results are different.
For the first query null is coming for unmatched records in the dept table
but in the second query, it does not come
Thank you
Hello
2947022 wrote:
Hi all
I use under version
Connected to Oracle Database 11g Express Edition Release 11.2.0.2.0
SQL > SELECT E.ENAME,.
2 D.DEPTNO,
3 D.LOC
4. TO EMP E,.
DEPT 5 D
6. WHERE = E.DEPTNO D.DEPTNO (+);
ENAME, DEPTNO LOC
---------- ------ -------------
DALLAS SMITH 20
ALLEN 30 CHICAGO
WARD 30 CHICAGO
20 DALLAS JONES
MARTIN 30 CHICAGO
BLAKE 30 CHICAGO
CLARK 10 NEW YORK
SCOTT 20 DALLAS
THE 10 NEW YORK KING
TURNER 30 CHICAGO
20 DALLAS ADAMS
JAMES 30 CHICAGO
FORD 20 DALLAS
MILLER 10 NEW YORK
40 BOSTON
15 selected lines
-----------------------------------------------------------------------------------------------------------------------------
SQL > SELECT E.ENAME,.
2 D.DEPTNO,
3 D.LOC
4. TO EMP E
5 LEFT OUTER JOIN
D 6 DEPT
7. THE E.DEPTNO = D.DEPTNO;
ENAME, DEPTNO LOC
---------- ------ -------------
MILLER 10 NEW YORK
THE 10 NEW YORK KING
CLARK 10 NEW YORK
FORD 20 DALLAS
20 DALLAS ADAMS
SCOTT 20 DALLAS
20 DALLAS JONES
DALLAS SMITH 20
JAMES 30 CHICAGO
TURNER 30 CHICAGO
BLAKE 30 CHICAGO
MARTIN 30 CHICAGO
WARD 30 CHICAGO
ALLEN 30 CHICAGO
14 selected lines
My doubt is both are same query is the same, is in ansi format and is in the format of the Oracle,.
but the results are different.
For the first query null is coming for unmatched records in the dept table
but in the second query, it does not come
Thank you
In fact, these requests are not the same.
The first is to find all the lines of the Department, with the corresponding lines of PGE (when there are). This is equivalent to «FROM dept LEFT OUTER JOIN emp...» ».
The second is to find all the rows in the emp of the lines of the Department (when there are any). This is equivalent to «...» WHERE e.deptno = d.deptno (+).
-
Bad result in a left outer join in 12.1.0.2
Hallo,
We discovered a strange behaviour in a query. The query provides values in a column of outer join where there is no corresponding value in the table is attached to the outside.
When you expand this request by the "ORDER BY" then this query gives the correct result.
Example:
SQL > desc tb_a
Name Null? Typ
-------------------------------------------- ----------------------------
ID NOT NULL NUMBER (19)SQL > desc tb_b
Name Null? Typ
-------------------------------------------- ----------------------------
CLOSED NOT NULL NUMBER (1)
ID NOT NULL NUMBER (19)CCS_APPLICATION@icw01> select * from tb_a where id in (4148,4141,4195);
ID
----------
4148
4141
4195CCS_APPLICATION@icw01> select * from tb_b where id in (4148,4141,4195);
INTERNAL ID
---------- ----------
4148 0CCS_APPLICATION@icw01> SELECT
2 b.id AS b_id,
3 a.id AS a_id,
4 b.closed AS b_closed
5
6 tb_a a
7 LEFT OUTER JOIN tb_b b ON a.id = b.id
8 WHERE a.id IN (4148, 4195, 4141)
9 ORDER BY ASC a.id
10;B_ID ALLOCATION A_ID B_CLOSED
---------- ---------- ----------
4141
4148 4148 0
4195CCS_APPLICATION@icw01> SELECT
2 b.id AS b_id,
3 a.id AS a_id,
4 b.closed AS b_closed
5
6 tb_a a
7 LEFT OUTER JOIN tb_b b ON a.id = b.id
8 WHERE a.id IN (4148, 4195, 4141)
9 - ORDER BY ASC a.id
10;B_ID ALLOCATION A_ID B_CLOSED
---------- ---------- ----------
4148 4148 0
4141 4141
4195 4195instance parameter:
VALUE OF TYPE NAME
------------------------------------ ----------- ------------------------------
compatible string 12.1.0.2.0
optimizer_features_enable string 12.1.0.2
After ""alter system set optimizer_features_enable = ' 11.2.0.4 ';" the query provides the correct result in both cases (ordered and unordered).
Now the final question: is this a bug?
1480970 wrote:
Hallo! Yes, I searched the Support of Oracle. I found some similar entries, but not an exact match. To fix some issues
with 12.1.0.2.
There is another interesting clue when look you on the execution plan:
Note
-----
-the dynamic statistics used: dynamic sampling (level = 2)
- This is an adaptation plan
We have disabled (= FALSE) optimizer_adaptive_features and the query provides the correct values.
This could be a solution for us.
Looks like a pretty tight match for bug 18430870, even if it affects the two 12.1.0.1 and 12.1.0.2, which contradicts the Martin trial against 12.1.0.1.
The description of the bug mentions disabling "_projection_pushdown" (set to false) should also be a viable solution, perhaps if you want to give that a try and see if it is a different bug or not.
There are also a number of one-time fixes already available for download, maybe your version / platform is already covered, if the bug applies.
Randolf
-
Hi Experts,
I have a requirement that says - see the chart for the past 10 days, regardless the presence data table in fact.
Lets consider an example - Time_dim product, are my dimension tables, Purchase_Order is my fact table.I did it for external Purchase_Order in left RPD with TIME_DIM and inner join with the PRODUCT table. and execution of query of exit-
Select T.Date, P.item, count (distinct PO.order_no)
TIME_DIM t, PRODUCT P, PURCHASE_ORDER PO
where T.date_key = PO.date_key
and P.item = in. agenda
and P.item = 'laptop ';The query generated by OBIEE left outer join, but when the condition P.item = "Notebook" included in the query, and if there are no orders for this product in one of the date, that date will not come in the result set.
the query to be generated by the OBIEE is-
Select T.Date, PO.item, count (distinct PO.order_no)
TIME_DIM t,.
(SELECT P.ITEM, IN. ORDER_NO
PRODUCT P, PO PURCHASE_ORDER
WHERE P.item = in. agenda
and P.item = 'Laptop') IN.
WHERE T.date_key = PO.date_key (+);How to design the RPD to achieve this. All pray to advise on this. Thanks in advance.
Thank you
ChantalHello
You are on 11.1.1.7?
I would say that your condition can be made without using external and maintenance of product and the standard between the FACT dimension, time inner join join.
If you enable your property analysis OBIEE "Include Null values" will automatically return all the elements of time and product matching your filter (so you'll need to add a filter on 'Date' to limit it to the last 10 days or you will have a unique day of your time dimension).
If you filter then on "Laptop", even if there is not a single value in order for "Laptop" in the last 10 days, he will be there on the screen.
Easy, clean and you keep your inner join between the facts and Dimensions.
Take a look at this example, I just did on SampleApp 406:
Selection of 12 months (year 2010) and a customer (id = 89) and income. The model has only an inner join. I activate the option "Include Null values" and here is the result.
A line with cells only empty because there is not a single revenue for customer 89 in 2010. This is exactly your condition.
Honestly, do not touch your model using the outer join, you will have more side effects than benefits. Every single scan will do the outer join and you'll have a lot of data 'empty' return of the DB (more large data set containing just the null values) and probably you need the outer join in 15 to 25% of your analysis.
Keep things simple, it will be faster and easier to maintain.
-
outer join with the additional constraint
Hello
With the help of Oracle 11 g R2.
I would of outer join tables 2 together and put down restrictions on the types of records that are returned in the query result. Here's a mock-up of the tables and data.
create table aaa (col1 number not null, col2 number not null)
create table bbb (col1 number not null, col2 number not null)
insert into values of aaa (1: 80)
insert into values aaa (2, 90)
insert into values aaa (3, 80)
insert into values aaa (4, 90)
insert into values aaa (5, 80)
insert into bbb values (3, 600)insert into values of bbb (4, 700)
This is the query
select a.col1, a.col2, b.col1, b.col2 from aaa a, bbb b where a.col1 = b.col1 (+) and (a.col2, b.col2) <> ((90, 700))
The result of the query is as follows.
col1 col1 col2 col2
1 80
3 80 3 600
5 80
Where col1 = 4 has been deleted, which is an expected result. However, where col1 = 2 has also been removed, which is not a desired outcome. Your response is appreciated.
Hello
Here is a way that works for the given sample data:
SELECT *.
AAA a
LEFT OUTER JOIN bbb b ON a.col1 = b.col1
WHERE the NVL (a.col2, 0) <> 90
OR NVL (b.col2, 0) <> 700
;
I don't know if that will satisfy your requirements with other data, since you didn't say what your needs are.
Whenever you have a WHERE clause is applied after the outer join, all columns of the table in option (table bbb in this example) must be used in an NVL, NVL2 or something like a CASE expression that takes into account null values; otherwise, the effect will be the same as an inner join.
-
Left Outer Join help...
Hello world
I'm still trying to learn the SQL, and I can not specifically with the left outer join. I normally join tables using equijoin, but I don't get the right data set returns, and designed with the help of a left or right outer join would solve the problem...
Here is my SQL that works properly with 1 left outer join. I build the slow query in the SQL following, you will see where I see the error. I don't expect you to understand the data and the columns, I'm trying to join, I think the problems I encounter are related to syntax, and I hope that you can find where are my syntax errors.
Select
s.Name as "Pseudonym,"
SV.view_name as "name of the view.
s_view. Name
Of
s s_screen,
s_screen_view sv
outer join left s_view
WE (sv.view_name = s_view.name)
where
SV.screen_id = ' 1-866 A - 1X3LU' and
s.ROW_ID = sv.screen_id and
s.repository_id = ' 866 A-1-1"and
s_view.repository_id = ' A-1-1 866 ";
Here is the SQL code where I encounter the following error...
Error:
ORA-00904: "SV". "" View_name ": invalid identifier
00904, 00000 - '% s: invalid identifier '.
* Cause:
* Action:
Error on line: column 14: 7
Problematic SQL:
Select
s.Name as "Pseudonym,"
SV.view_name as "name of the view.
s_view. Name,
s_applet. Name as Applet
-b.SID like "name of the cmdlet.
Of
s s_screen,
s_screen_view sv,
wti s_view_wtmpl_it
outer join left s_view
WE (sv.view_name = s_view.name)
outer join left s_applet
WE (wti.name = s_applet.name)
where
SV.screen_id = ' 1-866 A - 1X3LU' and
s.ROW_ID = sv.screen_id and
s.repository_id = ' 866 A-1-1"and
s_view.repository_id = ' A-1-1 866 ";
Thanks in advance for your help.
Chris
> ORA-00904: "S_VIEW_WEB_TMPL." "" ROW_ID ": invalid identifier
I don't see this table in your FROM clause.
-
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production 64-bit
With partitioning, OLAP, Data Mining and Real Application Testing options
When I run:
SELECT ACCF. SPECIMEN_ID as ACC_ID,
ACCF. PREFIX,
ACCF. SPECIMEN_NBR as ACC_NBR,
RP. PHYSICIAN_ID as REFPHY_BUS_KEY,
ACCF. SIGNOUTLOC,
THE. Location_id as LAB_BUS_KEY,
ACCF. COLLDATE as ACC_SPCMN_COLL_DT_ID,
ACCF. ACDATE as ACC_CREATED_DT_ID,
ACCF. SODATEORIG as ACC_ORIG_SIGNOUT_DT_ID,
ACCF. SODATE as ACC_SIGNOUT_DT_ID
OF ACC_FACT_WS ACCF.
REFPHY_WS RP,
THE LAB_WS
WHERE ACCF. BLINK = RP. PHYSICIAN_ID
AND ACCF. ACDATE > to_date('2010-06-17','YYYY-MM-DD')
AND ACCF. PREFIX = A '
AND ACCF. SIGNOUTLOC = (LOUISIANA). LOCATION_ID
It works fine, but I really have an outer join on LAB_WS.
When I run with an outer join, I get:
SQL > SELECT ACCF. SPECIMEN_ID as ACC_ID,
2 ACCF. PREFIX,
3 ACCF. SPECIMEN_NBR as ACC_NBR,
4. PR PHYSICIAN_ID as REFPHY_BUS_KEY,
5 ACCF. SIGNOUTLOC,
6. THE. Location_id as LAB_BUS_KEY,
ACCF 7. COLLDATE as ACC_SPCMN_COLL_DT_ID,
ACCF 8. ACDATE as ACC_CREATED_DT_ID,
ACCF 9. SODATEORIG as ACC_ORIG_SIGNOUT_DT_ID,
ACCF 10. SODATE as ACC_SIGNOUT_DT_ID
11 ACC_FACT_WS ACCF,
12 REFPHY_WS RP
13 LEFT OUTER JOIN LAB_WS ON ACCF. SIGNOUTLOC = (LOUISIANA). LOCATION_ID
14. WHERE ACCF. BLINK = RP. PHYSICIAN_ID
15 AND ACCF. ACDATE > to_date('2010-06-17','YYYY-MM-DD')
16 AND ACCF. PREFIX = A ';
LEFT OUTER JOIN LAB_WS ON ACCF. SIGNOUTLOC = (LOUISIANA). LOCATION_ID
*
ERROR on line 13:
ORA-00904: "ACCF. "" SIGNOUTLOC ": invalid identifier
The previous query shows ACCF. SIGNOUTLOC is not the problem.
What is the problem and how to fix it?
Note: the syntax of the old outer join is not an option. The query will be finally 9 outer joins.
Thank you
Jon JacobsHello
You are mixing syntax to join Oracle with ANSI, which is sometimes delicate.
Best is to use a unique syntax, for example ANSI:... FROM ACC_FACT_WS ACCF JOIN REFPHY_WS RP ON ACCF.CLIN = RP.PHYSICIAN_ID LEFT OUTER JOIN LAB_WS LA on ACCF.SIGNOUTLOC = LA.LOCATION_ID WHERE ACCF.ACDATE > to_date('2010-06-17','YYYY-MM-DD') AND ACCF.PREFIX = 'D'
Maybe you are looking for
-
Re: I have to restart the U400 Satellite to make sure that all parameters are correctly
First of all, I started my new U400.However, after recording of Windows and Toshiba Quarantee, (toshiba message) system keeps showing a warning/info after every time that I reboot I should reboot again to check if all the settings are installed corec
-
Hello I have a code that sends a "* IDN? GPIB addresses 1 to 31, if I get a response to the motion, I guess there is a GPIB device address. This approach gets watered until when I have a GPIB instrument does does support/recognize the * IDN? query.
-
I have a Lexmark X 1150 with a gateway DX4200 amd 9100E computer, with windows Vista. I can print from my computer to the internet programs or word examples, my problem is when I try to scan from the printer to the computer, I get the following: prep
-
I have time picker when I select the time from the time picker, time will display on the look of the label on the peak. but when I click the ESC key to close the time picker, time will display in the label, mean when I close the timepicker, it closes
-
My machine is too old to run Windows 8?
I have an old OEM Office of as 2010.Initially, it came with Vista Home Basic, but then I've upgraded to Windows 7.The upgrade worked. The machine worked well.So I guess he could manage Windows 8 too.It is an emachines t3656.The specifications are Int