left outer join and the where clause for the table to the right
I want to join two tables a and b, where a is a must and b is a result set in option. When I use a left outer join to a to b, I want to achieve:1. Select a single column, two columns of b (not the join columns)
2 - even if theres no friendly on the join column does not return data from one.
3. If there is a match applies when the criteria on column b (table in option)
so, how can I avoid no_data_found in this case? When I apply where criteria for b, so it does not return the data from one, which is a must.
Sounds like a regular outer join to me...
select a.col1, b.col2, b.col2
from tableA a
left outer join tableB b
on (a.id = b.id and b.colX = 'X')
Tags: Database
Similar Questions
-
Difference-conditions (join and a Where Clause)
Hi people,
I need to clearly agree on what a difference exactly when we put any condition in INNER JOIN and the WHERE Clause.
I have tried both way and found the same results. Even in the statistics Plan not much differences. Any help would be appreciated.
As:
1 here, I use filter store in the join condition - Inner
"SELECT i., Gl * Sc1.Item I.
Inner Join Sc1.Part P
On P.Part_Id = I.Part_Id
Inner Join Sc1.Location Gl
On Gl.Location_Id = I.Location_Id
And Gl.Location_Id in (1767, 1747,202,1625)
Inner Join Sc1.Condition C
On C.Condtion_Id = Gl.Condition_Id
Where I.Inactive_Ind = 0
And I.Condition_Id! = 325
2. here I use filter store in Where clause-
SELECT i., Gl * Sc1.Item I
Inner Join Sc1.Part P
On P.Part_Id = I.Part_Id
Inner Join Sc1.Location Gl
On Gl.Location_Id = I.Location_Id
Inner Join Sc1.Condition C
On C.Condtion_Id = Gl.Condition_Id
Where I.Inactive_Ind = 0
and I.LOCATION_ID in (1767, 1747,202,1625)
And I.Condition_Id! = 325
Thank you
Mark
Hello
MarkCooper wrote:
Hi guys,.
To reply to all - I understand.
1. its good practice to use conditions / filter (except CLAUSE) in the WHERE Clause rather Inner join? bon ?
2. now, in my previous example. We could use the location code in where clause as it was in the two tables.
What is the best practice to use the code to location here ( 1 /2) ?
1. here I use filter store in the Inner join condition ( guess the location code is not in the article table)).
"SELECT i., Gl * Sc1.Item I.
Inner Join Sc1.Part P
On P.Part_Id = I.Part_Id
Inner Join Sc1.Location Gl
On Gl.Location_Id = I.Location_Id
And Gl.Location_Id in (1767, 1747,202,1625)
Inner Join Sc1.Condition C
On C.Condtion_Id = Gl.Condition_Id
Where I.Inactive_Ind = 0
And I.Condition_Id! = 325
2. here I use filter store in Where clause (assume that the location code is not in the article table)-
SELECT i., Gl * Sc1.Item I
Inner Join Sc1.Part P
On P.Part_Id = I.Part_Id
Inner Join Sc1.Location Gl
On Gl.Location_Id = I.Location_Id
Inner Join Sc1.Condition C
On C.Condtion_Id = Gl.Condition_Id
Where I.Inactive_Ind = 0
And Gl.Location_Id in (1767, 1747,202,1625)
And I.Condition_Id! = 325
Thank you
If location_id isn't in the item table, then the join condition
On Gl.Location_Id = I.Location_Id
will cause an error.
Once more, it should not affect results or performance if a condition like
Gl.Location_Id in (1767, 1747,202,1625)
is in the clause or the WHERE clause. No matter if it is be a column called location_id in any other table, or if the same column Gl.Location_Id is used in other conditions.
As this condition only refers to a table (GI), I recommend you put it in a WHERE clause, just to make the code clearer.
Yet once, this applies only to the inner joins, not for outer joins and not to CONNECT BY queries.
-
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 Outer join and filter
Hello
I join two tables in the source using a left outer join. Outside of the join, I have a filter specified with condition TabA.C1 > TabB.C2.
Now, when ODI generates the query it puts the left outer join on the filter condition as well. So he puts filter as
where
(1 = 1)
And ((TabA.C1 = TabB.C1 (+)) AND)
(TabA.C2 = TabB.C2 (+))
And TabA.C10 > TabB.C14 (+)
How to avoid this problem. I tried this performance on stage as well, always generated query remains the same.
I use the incremental update of the IKM Oracle. My source and target are both on the same PB.
~ ChikkHi Chikk,
If you analyze the data, you'll see it's OK to have the "(+)" to the filter...
Anyway, if you want to drop it, leave it as inner join and put the "(+)" manually to the join object.
This help you?
-
Outer joins and null in the 'where' clause condition
Hi people,
Please help me on this.
Here's my query.
with x
(select 'a' as a dual union all col1)
Select 'b' as col1 of union double all the
Select 'c' as double col1
),
y as
(
Select 'b' as col2 from dual Union all the
Select 'c' as col2 from dual Union all the
Select would be "as col2 from dual Union all the"
Select 'e' as col2 from dual
)
Select * x y right outer join
on x.col1 = y.col2 and y.col2 is null
Get all the lines of 'COL1' as null. Why like this?
Just add the condition to the WHERE clause for example
WITH x AS (SELECT 'a' AS col1 FROM dual UNION ALL SELECT 'b' AS col1 FROM dual UNION ALL SELECT 'c' AS col1 FROM dual ), y AS ( SELECT 'b' AS col2 FROM dual UNION ALL SELECT 'c' AS col2 FROM dual UNION ALL SELECT 'd' AS col2 FROM dual UNION ALL SELECT 'e' AS col2 FROM dual ) SELECT * FROM x LEFT OUTER JOIN y ON x.col1=y.col2 ----want to add "and y.col2 is null " condition to get value "a" where y.col2 is null
-
What is the difference between NOT IN and LEFT OUTER JOIN
Hello
I searched the difference between everywhere. But his powerlessness.
Please tell me the differences.
Thanks in advance
KVBIt's like comparing apples and oranges.
NOT IN - exclude all lines matching the condition NOT IN (beware of NULL values).
JOIN EXTERNAL - return of rows from the inner table even if there is no corresponding row in the outer table.
SQL> -- NOT IN SQL> with x as 2 (select 1 col1 from dual union all 3 select 2 col1 from dual union all 4 select 3 col1 from dual) 5 , y as 6 (select 1 col1 from dual) 7 select * 8 from x 9 where col1 not in (1,2); COL1 ---------- 3 SQL> -- NOT IN (subquery) SQL> SQL> with x as 2 (select 1 col1 from dual union all 3 select 2 col1 from dual union all 4 select 3 col1 from dual) 5 , y as 6 (select 1 col1 from dual) 7 select * 8 from x 9 where col1 not in (select col1 from y); COL1 ---------- 2 3 SQL> -- OUTER JOIN SQL> with x as 2 (select 1 col1 from dual union all 3 select 2 col1 from dual union all 4 select 3 col1 from dual) 5 , y as 6 (select 1 col1 from dual) 7 select * 8 from x 9 left outer join 10 y 11 on x.col1 = y.col1; COL1 COL1 ---------- ---------- 1 1 3 2 SQL> -- Maybe it helps to contrast LOJ with just JOIN? SQL> with x as 2 (select 1 col1 from dual union all 3 select 2 col1 from dual union all 4 select 3 col1 from dual) 5 , y as 6 (select 1 col1 from dual) 7 select * 8 from x 9 join y 10 on x.col1 = y.col1; COL1 COL1 ---------- ---------- 1 1 SQL>
-
Outer joins to the left... Please help!
Hmm. Ive had trouble with this one for a while and have read and re-read docs etc.
IM under 11.2 XE and its Apex 4.2 application...
Its a simple query with outer joins... but I can't simply to do it right after several hours of trying! ID be very grateful if anyone can lend a hand...
For the query below. I am looking for the following:
Complete list of entities, a sum of the values if they exist (and obviously empty if they don't), filtered by a table of SUM choice only the records that match a value in the lookup table.
Select
e.ENTITY as ENTITY,
Sum (p.amount) as Forecast_Income,
Sum (BR.bri_credit) as Actual_Income,
Sum (BR.bri_debit) as Actual_Expenses
Of
e entities
LEFT OUTER JOIN payments p
WE (e.entity_id = p.entity_id)
LEFT OUTER JOIN pmt_stat_lookup ps
WE (p.status_id = ps.status_id
and ps.forecast = 'Y')
LEFT OUTER JOIN bri_recon br
WE (e.entity_id = br.entity_id)
E.entity group
My problem with the join where I join p.status_id for ps.status_id and ps.forecast = 'Y '... If I run the above statement, it seems does not account for this filter criteria and summarizes all records of PAYMENTS, regardless of... If I move outside the outer join clause, it only brings back the records of PAYMENTS where there is a join. Ive tried to join in a different order etc... but in vain...
If someone could help, Id be very grateful.
Kind regards
Richard
Hello Richard
Try this query:
SELECT e.entity as ENTITY
sum (PO.amount) as Forecast_Income
sum (br.bri_credit) as Actual_Income
sum (br.bri_debit) as Actual_Expenses
Of
E ENTITIES
LEFT OUTER
JOIN (SELECT P.entity_id )
P.amount
PAYMENTS P
JOIN PMT_STAT_LOOKUP PS
ON p.status_id = ps.status_id
AND ps.forecast = 'Y '.
) IN.
WE e.entity_id = in. entity_id
LEFT OUTER
JOIN BR BRI_RECON
ON e.entity_id = br.entity_id
E.entity GROUP
;
I hope it helps.
Best regards, David
Post edited by: David Berger
-
Help for a LEFT OUTER JOIN query
Hello, all,.
I'm having some trouble setting up an Oracle 11 g Server SQL query, and I could use some help.
Let's say tableA is blogs; tableC is comments for blog entries; tableB is the associative array:
tableA blogID blogTitle blogBody dateEntered 1 This is a test More text... 2016-05-20 11:11:11 2 More testing Still more! 2016-05-19 10:10:10 3 Third charm!! Blah, blah. 2016-05-18 09:09:09
tableC commID userID userText dateEntered 10 Bravo I like it! 2016-05-20 11:21:31 11 Charlie I don't! 2016-05-20 11:31:51 12 Alpha Do it again! 2016-05-19 10:20:30 13 Bravo Still more? 2016-05-19 10:30:50 14 Charlie So, what? 2016-05-19 10:35:45 15 Bravo Blah, what? 2016-05-18 09:10:11 16 Alpha Magic number! 2016-05-18 09:11:13
tableB blogID commID 1 10 1 11 1 12 2 13 2 14 3 15 3 16
I'm trying to get blogID, blogTitle, blogBody and the number of comments for each blog entry. But, since I'm on to_char() for date and COUNT (commID) for the total number of comments, I am not "a group by expression.
Here is an example of pseudo-SQL of what I'm trying.
SELECT a.blogID, a.blogTitle, a.blogBody, to_char(a.dateEntered,'YYYY-MM-DD HH24:MI:SS') as dateEntered, COUNT(c.commID) as total FROM tableA a LEFT OUTER JOIN tableB b ON b.blog_ID = a.blog_ID LEFT OUTER JOIN tableC c ON c.commID = b.commID WHERE a.blogID = '1' GROUP BY blogID, blogTitle, blogBody ORDER BY to_date(dateEntered,'MM-DD-YYYY HH24:MI:SS') desc
I'm sure it's something simple, but I just DO NOT see it. Can you help me?
V/r,
^_^
Try:
GROUP BY a.blogID, a.blogTitle, a.blogBody, to_char(a.dateEntered,'YYYY-MM-DD HH24:MI:SS')
See you soon
Eddie
-
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.
-
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,
^_^
-
Modeling of the left outer join
Hello world
I'm tender hand to you guys for a modeling help
I have a FACT, the customers, the Dim_Date and CUST_ADDRESS of tables to model
Fact and the client are joined through CUST_ID
FACT and DATE are joined through DATE_ID
CUST_ADDRESS must be attached to the top of the model through CUST_ID, DATE_ID and this join must be Left outer because sometimes the address does not exist or is not current, which means DATE_ID could be different between Dim_Date and CUST_ADDRESS
If it were to join internal, model would have been easy, because of the outside left that I am unable to model, it's pretty good.
Application under
Select D.DATE, C.CUST_NAME, CA. ADDRESS, F.AMOUNT
Of
F FACT
JOIN THE
CUSTOMER C
ON C.CUST_ID = F.CUST_ID
JOIN THE
DIM_DATE D
ON F.DATE_ID = D.DATE_ID
LEFT OUTER JOIN
CUST_ADDRESS CA
ON C.CUST_ID = CA. CUST_ID AND C.DATE_ID = D.DATE_IDThanks in advance
When I add the CUSTOMER and in FACT LTS CUST_ADDRESS
Stop it!
Don't add CUSTOMER and CUST_ADDRESS in the FACT of LTS. Why would add you to the LTS DO?
You design a management model: CUSTOMER is a dimension and it has its own logical table this logic table join with a logical join in the activity diagram. Ditto for CUST_ADDRESS.
So the change, I missed earlier is CUST_ADDRESS contains no Cust_ID (ACTUALLY existing), but contains a Cust_NO, and the table to translate Cust_NO in Cust_ID is CUSTOMER?
No problem...
Let's start with a new alias of CUSTOMER (to keep more simple to understand at the moment), call as you want, but this new alias will be the link between the FACT and CUST_ADDRESS.
In LTS of the dimension 'Address', you have CUST_ADDRESS initially, add an inner join on the new alias that you created in the LTS of the CUSTOMER. So now your 'Address' logical dimension contains the Cust_NO and Cust_ID and this will make the join to FACT.
Between CUST_ADDRESS and the CLIENT, you can keep an inner join, because the target is not not for get the address of the customer, but is having the Cust_ID in the address line.
Give it a try at that.
But do not add these tables in the LTS, they are logical dimensions.
-
outer join on the left, needs improvement
Two table t1 and t2 where t1.col1 = t2.col2
real to come resultcreate table t1 ( col1 varchar2(20)); insert into t1 values('aa'); insert into t1 values('bb'); insert into t1 values('cc'); insert into t1 values('dd'); insert into t1 values('ee'); create table t2 ( col2 varchar2(20) , col3 varchar2(20)); insert into t2 values('aa','q_aa'); insert into t2 values('bb',' '); insert into t2 values('cc','q_cc'); insert into t2 values('dd',' '); here is my join query:- select t1.col1,t2.col2,t2.col3, case when t2.col3 is not null then t2.col3 when t2.col3 is null then t1.col1 end as name1 from t1 left outer join t2 on t1.col1 =t2.col2
COL1 ^ ^ COL2 ^ ^ COL3 ^ ^ NAME1
AA ^ ^ ^ aa ^ ^ ^ q_aa ^ ^ ^ q_aa
BB ^ ^ ^ bb
CC ^ ^ ^ cc ^ ^ ^ q_cc ^ ^ ^ q_cc
JJ ^ ^ ^ JJ
ee^^^^^^^^^^^^^^^^ee
requirement of result
COL1 ^ ^ COL2 ^ ^ COL3 ^ ^ ^ NAME1
AA ^ ^ ^ aa ^ ^ ^ q_aa ^ ^ ^ q_aa
BB ^ ^ ^ bb ^ ^ ^ bb
CC ^ ^ ^ cc ^ ^ ^ q_cc ^ ^ ^ q_cc
JJ ^ ^ ^ DD ^ ^ ^ JJ
ee^^^^^^^^^^^^^^^^^ ee
and how can copy paste the result of sql * more... box when I copy paste here it automatically omit the space, as aboveThe problem is values col3 to the 'bb' and 'dd' lines are not null, because they have a space in them. You can either remove the space and use:
nvl(t2.col3,t1.col1) as name1
or tim space out:
nvl(trim(t2.col3),t1.col1) as name1
-
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
-
SSRS for lack of outer join with the Oracle data source
It seems to be a problem with the Oracle driver used in the Reporting SERVICES query designer.
When you use an Oracle data source, if I create an outer join in the graphic designer, it automatically inserts '{OJ' before the join and '} ' after her. This is an incorrect syntax for Oracle and refuses to start. The curly braces and the JO editable in designer text, but if I go back to the graphic designer and immediately to reintegrate them.
Only, this has started to happen a year or two ago - before that it worked, but with the old (+) syntax.
Can it not be healed? It makes things very difficult.
-Geoff
Hi Geoff,
Thanks for posting in the Microsoft Community.
However, the question you posted would be better suited in the Forums of the Oracle Support; We recommend that you post your query in Oracle Support Forums to get help:
If you have any other questions or you need Windows guru, do not hesitate to post your questions and we will be happy to help you.
-
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.
Maybe you are looking for
-
iPhone battery indicator 6 s is still not exact
I think that iOS 9.3 update was supposed to fix the problem where the iPhone 6 and 6 s more the battery indicator are not accurate. I'm under 9.3, but still see the same symptoms, or a fall of 3% at the same time, or turn off completely with 10-15% l
-
Re: Satellite L300 - how to reinstall the SATA drivers?
Hi all I have a L300 I downgraded to XP. It runs with the SATA controller in compatibility mode and are sent here a lot, it's slow. I read you need drivers intel for her and so I downloaded the and down them and had an error "your computer does not m
-
Need manual for portable Satellite L40
I downloaded the user manual for portable Satellite L40 series, but it is damaged :(Could someone send me the manual?my mail: [email protected] Kind regards!
-
The Windows Update components fail to install
This morning I noticed that in the past 2 windows update components were not installed. The table below shows the number of the knowledge base for patches and their associated error codes. Title Knowledge Base number Error code Update for 2007 Micros
-
Errors on Windows Vista KB2470478 ESENT
I am running Windows VISTA Ultimate SP2. I've had this laptop for about 4 years and have upgraded memory and drives without incident selection until I recently updated to a new 1 TB of HARD drive. I now receive errors of ESENT this update of Window