Problem with ANSI OUTER JOIN
Hi allI have issues with the help of ANSI LEFT JOIN compared to Oracle (+). Below test I did the same thing.
create table emp (emp_id number(10), emp_name varchar2(50));
create table courses (course_id number(10), emp_id number(10), course_name varchar2(50));
INSERT INTO EMP values(1,'A');
INSERT INTO EMP values(2,'B');
INSERT INTO EMP values(3,'C');
INSERT INTO COURSES values(1,1,'ORACLE');
INSERT INTO COURSES values(2,1,'JAVA');
INSERT INTO COURSES values(3,3,'C#');
--*Query 1
SELECT a.*, b.*
FROM EMP a LEFT JOIN COURSES b
ON a.emp_id = b.emp_id
AND a.emp_name = 'A'
--*Query 2
SELECT a.*, b.*
FROM EMP a, COURSES b
where a.emp_id = b.emp_id(+)
and a.emp_name = 'A'
Here Query1 return all records of 4 same records regardless of emp_name = 'A' where as Query2 returns 2 records of ep_name = 'A' which is correct.Is this correct? I'm confused if you use the standard ANSI OUTER JOINS or not.
I am using Oracle 11g
Thank you.
Change your AND WHERE, in the style of ANSI, select:
SELECT a.*, b.*
FROM EMP a LEFT JOIN COURSES b
ON a.emp_id = b.emp_id
WHERE a.emp_name = 'A'
Filters in the clause are those who use the (+) in the Oracle syntax.
Filters WITHOUT (+) in the Oracle syntax should be in the WHERE clause using the ANSI syntax.
Published by: Kim Berg Hansen on September 23, 2011 08:03
Tags: Database
Similar Questions
-
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
-
Hello
I'm on Oracle 10.2.0.4.
I have a problem with a simple Cartesian join. Is it possible to have a Cartesian join? whether a table has data and another table has no data, I take a Cartesian join (no join condition), I want to see all records from a table and values NULL for columns from the other table.
For example
SQL > create table T1 (id number, emp_name varchar2 (30));
Table created.
SQL > create table T2 (sp_name varchar2 (10), sp_desc varchar2 (10));
Table created.
SQL > insert into T1 values (101, 'AAAAA');
1 line of creation.
SQL > insert into T1 values (102, 'BBBB');
1 line of creation.
SQL > insert into values of T2 ('TBT', 'Important');
1 line of creation.
SQL > insert into values of T2 ("XYZ", "Not good");
1 line of creation.
SQL > commit;
Validation complete.
SQL > select t1.id, t1.emp_name, t2.sp_desc
2 from t1, (select sp_name, sp_desc from t2 where sp_name = "OTC") t2;
ID EMP_NAME SP_DESC
---------- ------------------------------ ----------
AAAAA 101 Important
Important 102 BENAMER
SQL > select t1.id, t1.emp_name, t2.sp_desc
2 from t1, (select sp_name, sp_desc from t2 where sp_name = "ZZZ") t2;
no selected line
SQL >
In the second query (where no line is selected), I want to see all the records in the table T1 and NULL values in columns from the alias of table T2.
How can I do?
Thanks in advance
The ANSI syntax can help here.
Select t1.id, t1.emp_name, t2.sp_desc
from t1
outer join t2 left t2.sp_name = "OTC";
ID EMP_NAME SP_DESC
---------- ------------------------------ ----------
AAAAA 101 Important
Important 102 BENAMER
Select t1.id, t1.emp_name, t2.sp_desc
from t1
outer join t2 left t2.sp_name = "ZZZ";
ID EMP_NAME SP_DESC
---------- ------------------------------ ----------
AAAAA 101
BENAMER 102
Post edited by: Brian Bontrager
removed the unnecessary condition -
records with an outer join restrictions while using a sub query?
I have the following code:
declare
Default char Activeonly ' n ';
SearchKey varchar2 (15) default '413041494500064';
number of lclAcctNo;
Start
Select
rat_acct_no in lclAcctNo
ACCT,.
marketer_account ma1,
Marketing agent,
Account_Service,
Account_Address
Where (Rat_Acct_No = Mka_Acct_No
and Mka_Exp_Dt = (ma2 select Max (Mka_Exp_Dt) of Marketer_Account
Where Mka_Acct_No = Rat_Acct_No)
and mka_service_type = 'E')
And Rat_Acct_No = Acs_Acct_No
And Rat_Acct_No = Add_Acct_No
"And Add_Address_Type s ="
And Rat_Full_Css_Acct_No as Trim (Searchkey) | '%'
And (Activeonly is Null or Activeonly = ' or (Rat_Acct_Status_Cd = 'A' or Rat_Acct_Status_Cd is Null))
and rownum < 1000;
dbms_output.put_line ('Account' | lclAcctNo);
end;
I'm doing the table MARKETER_ACCOUNT (MKA_fields) an outer join, because the data I expect to will not be on the table, but I want even when the table of ACCT.
I can't do an outer join on subqueries, so wanted to know if there was a way more easy/better to Edifier cela?
I use Oracle 11.2 g.
Thanks for any help.
Sean
Basically, I think, your outer join is ruined by the subquery correlated in the WHERE clause:
R.ToDate = (Select MAX(ToDate) from R r2
Since you joined outside R to A tell you the database to give you the lines of A for which R.ToDate is null * AND * meets your requirement: and this is not possible. Tom Kyte gave the classic explanation for this kind of problem long ago on AskTom: http://asktom.oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:4963137609733 ("ask yourself this - how a row in T2 (EMP in your example) the MISSING two (composed due to the outer join) AND have a column that corresponds to something?") It cannot be").
Here's your example in DDL + DML form: ''
create table account)
VARCHAR2 (10) key
, name varchar2 (10)
, status varchar2 (10)
);
insert into account values ('A1', 'John', 'Active');
insert into account values ('A2', 'Mary', 'Active');
insert into account values ('A3', 'James', 'Inactive');
Create array of marketing)
VARCHAR2 (10) key
, Varchar2 (10) Mktr
);
insert into values Marketer ("M1", "ABC");
insert into values Marketer ("M2", "DEF");
create table relationship)
VARCHAR2 (10) key
, Varchar2 (10) AccKey
, MktKey varchar2 (10)
, FromDt varchar2 (10)
, Varchar2 (10) so far
);
insert into the relationship values ('R1', 'A1', 'M1', "" 01/01/2012 ', December 31, 2012 ' ");
insert into the relationship values ('R2', 'A1', 'M2', "01/01/2013 ', 'present'");
insert into the relationship values ('R3', 'A2', 'M2', ' 01 /' 02/2013, 31 / 05/2013 ');
Select B.SID
M.Mktr
R.FromDt
R.ToDate
account A
left join
relationship R
on (a.Key = R.AccKey)
left join
Distributor M
on (R.MktKey = M.Key)
where R.ToDate = (Select MAX (r2. To date)
relationship r2
where r2. AccKey = A.Key)
and A.Status = 'Active '.
;
MKTR FROMDT NAME DATE
---------- ---------- ---------- ----------
Mary DEF 2/1/2013 5/31/2013
John DEF 01/01/2013 presents
-a possibility to obtain all the relevant lines would be to perform filtering after the join:
with
BaseData as)
Select B.SID
A.key
M.Mktr
R.FromDt
R.ToDate
account A
left join
relationship R
on (a.Key = R.AccKey)
left join
Distributor M
on (R.MktKey = M.Key)
)
Select basedata.*
of basedata
where basedata. ToDate = (Select MAX (r2. To date)
relationship r2
where r2. AccKey = basedata. Key)
or basedata. This day is null;
KEY MKTR FROMDT NAME DATE
---------- ---------- ---------- ---------- ----------
Mary A2 DEF 2/1/2013 5/31/2013
John A1 DEF 01/01/2013 presents
James A3
Of course, there are many other possible solutions - since it's SQL...
Concerning
Martin
-
[8i] need help with full outer join combined with a cross join...
I can't understand how to combine a full outer join with a different type of join... is it possible?
Here are some create table and insert for examples of database:
And, the results that I want to get: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);
I tried a number of different things, google my problem and no luck yet...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 4
So, what I want, it's a full outer join of t1 and t2 on workstation and a cross join of one with the t3. I wonder if I can't find examples of it online because it is not possible...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 ...
Note: I'm stuck dealing with Oracle 8i
Thank you!!Hello
The query I posted yesterday is a little more complex that it should be.
My_tab2.workstation is unique, there is no reason to make a separate subquery as mt1. We can join my_tab1 to my_tab2 and get the SUM in a subquery.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, and very clear expected results!
user11033437 wrote:
... So, what I want, it's a full outer join of t1 and t2 on workstation and a cross join of one with the t3.She, exactly!
The trickiest part is when and how get SUM (my_value). You could address the question of exactly what my_tab3 must be attached to a cross that's exactly what should look like the result set of the full outer join between my_tab1 and my_tab2 to. To do this, take your desired results, remove columns that do not come from the outer join complete and delete duplicate rows. You will get:workstation sum(my_value) wkstn_name ----------- ------------- ---------- ABCD 30 WKSTN 1 A123 35 WKSTN 2 B456 0 WKSTN 3 ???? 5 NULL
So the heart of the problem is how to get these results of my_tab1 and my_tab2, which is done in the subquery FOJ above.
I tried to use auto-documenté in my code names. I hope you can understand.
I could spend hours explaining the different parts of this query more in detail, but I don't know that I would lose some of that time, explain things that you already understand. If you want an explanation of the specific element (s), let me know. -
Bug with an outer join, or &; Analytics function (or rownum)
Hello
Seems to be a combination of an outer join, OR and rownum confuses the CBO.
First request is without rownum, the second is with rownum.
The second query expects 203 t lines and never ends. It should behave the same as query 1, with 24 M lines.
Remove the GOLD clause query 2 allows him to behave as a query 1, with 24 M lines.
We never saw it? Is there a solution?
SELECT * FROM message i LEFT JOIN (SELECT hi.message_id, hi.update_dt FROM message_hist hi) h ON (t.id = h.master_id AND(t.update_dt = h.update_dt OR h.update_dt <TO_DATE('150901','RRMMDD'))); ----------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ----------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 24M| 13G| 475G (2)|999:59:59 | | 1 | NESTED LOOPS OUTER | | 24M| 13G| 475G (2)|999:59:59 | | 2 | TABLE ACCESS FULL | MESSAGE | 8037K| 1318M| 29883 (2)| 00:06:59 | | 3 | VIEW | | 3 | 1302 | 59136 (2)| 00:13:48 | |* 4 | TABLE ACCESS FULL| MESSAGE_HIST | 3 | 168 | 59136 (2)| 00:13:48 | ----------------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 4 - filter("I"."MESSAGE_ID"="HI"."MESSAGE_ID" AND ("HI"."UPDATE_DT"<TO_DATE('150901','RRMMDD') OR "I"."UPDATE_DT"="HI"."UPDATE_DT")) ---------------- SELECT * FROM message i LEFT JOIN (SELECT hi.message_id, hi.update_dt , ROWNUM FROM message_hist hi) h ON (t.id = h.master_id AND(t.update_dt = h.update_dt OR h.update_dt <TO_DATE('150901','RRMMDD'))); ------------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 203T| 112P| 475G (2)|999:59:59 | | 1 | NESTED LOOPS OUTER | | 203T| 112P| 475G (2)|999:59:59 | | 2 | TABLE ACCESS FULL | MESSAGE | 8037K| 1318M| 29883 (2)| 00:06:59 | | 3 | VIEW | | 25M| 10G| 59151 (2)| 00:13:49 | |* 4 | VIEW | | 25M| 10G| 59151 (2)| 00:13:49 | | 5 | COUNT | | | | | | | 6 | TABLE ACCESS FULL| MESSAGE_HIST | 25M| 1355M| 59151 (2)| 00:13:49 | ------------------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 4 - filter("I"."MESSAGE_ID"="H"."MESSAGE_ID" AND ("I"."UPDATE_DT"="H"."UPDATE_DT" OR "H"."UPDATE_DT"<TO_DATE('150901','RRMMDD')))
RowNum in a subquery is supposed to ensure that the subquery is evaluated completely before filtering, otherwise, how could you go out rownum?
Your question is compounded because of the join condition that forces a level of nested loops, which means that the table should be fully analysed once for each line of conduct rowsource. You can either transform the join in an equijoin and allow a hash to run, or you join could materialize the subquery once.
Allow the hash join:
SELECT count (*)
Message FROM
LEFT JOIN (SELECT hi.message_id, hi.update_dt
ROWNUM
OF message_hist salvation) PM ON (i.message_id = h.message_id
AND i.update_dt = h.update_dt)
LEFT JOIN (SELECT hi.message_id, hi.update_dt
ROWNUM
OF message_hist salvation) h2 ON (i.message_id = h2.message_id
AND h2.update_dt<>
AND h2.update_dt <> i.update_dt)
/
----------------------------------------------------------------------------------------
| ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time |
----------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1. 66. 211 (1) | 00:00:01 |
| 1. GLOBAL TRI | | 1. 66. | |
|* 2 | EXTERNAL RIGHT HASH JOIN | | 800 | 52800 | 211 (1) | 00:00:01 |
|* 3 | VIEW | | 1. 22. 70 (0) | 00:00:01 |
| 4. COUNTY | | | | | |
| 5. TABLE ACCESS FULL | MESSAGE_HIST | 1. 22. 70 (0) | 00:00:01 |
|* 6 | EXTERNAL RIGHT HASH JOIN | | 800 | 35200. 141 (1) | 00:00:01 |
| 7. VIEW | | 1. 22. 70 (0) | 00:00:01 |
| 8. COUNTY | | | | | |
| 9. TABLE ACCESS FULL | MESSAGE_HIST | 1. 22. 70 (0) | 00:00:01 |
| 10. TABLE ACCESS FULL | MESSAGE | 800 | 17600 | 70 (0) | 00:00:01 |
----------------------------------------------------------------------------------------
Information of predicates (identified by the operation identity card):
---------------------------------------------------
2 - access("I".") MESSAGE_ID '= 'H2'.' MESSAGE_ID "(+))"
filter ("H2". "UPDATE_DT" (+)<>'I'. " ("' UPDATE_DT")
3 - filter("H2".") UPDATE_DT "(+)<>
6 - access("I".") "UPDATE_DT" ="H" UPDATE_DT "(+) AND"
"I"." ' MESSAGE_ID ' ="H" MESSAGE_ID "(+))"
Materialize the subquery:
WITH h AS (SELECT / * + MATERIALIZE * / hi.message_id, hi.update_dt)
ROWNUM
OF message_hist salvation)
SELECT count (*)
Message FROM
LEFT JOIN: ON (i.message_id = h.message_id
AND (i.update_dt = h.update_dt OR h.update_dt<>
----------------------------------------------------------------------------------------------------------
| ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time |
----------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1. 22. 1740 (0) | 00:00:01 |
| 1. TRANSFORMATION OF THE TEMPORARY TABLE. | | | | |
| 2. LOAD SELECT ACE | SYS_TEMP_0FD9D6810_5B8F6E67 | | | | |
| 3. COUNT | | | | | |
| 4. TABLE ACCESS FULL | MESSAGE_HIST | 1. 22. 70 (0) | 00:00:01 |
| 5. GLOBAL TRI | | 1. 22. | |
| 6. NESTED EXTERNAL LOOPS | | 800 | 17600 | 1670 (0) | 00:00:01 |
| 7. TABLE ACCESS FULL | MESSAGE | 800 | 17600 | 70 (0) | 00:00:01 |
| 8. VIEW | | 1. | 2 (0) | 00:00:01 |
|* 9 | VIEW | | 1. 22. 2 (0) | 00:00:01 |
| 10. TABLE ACCESS FULL | SYS_TEMP_0FD9D6810_5B8F6E67 | 1. 22. 2 (0) | 00:00:01 |
----------------------------------------------------------------------------------------------------------
Information of predicates (identified by the operation identity card):
---------------------------------------------------
9 - filter("I".") ' MESSAGE_ID ' ="H" MESSAGE_ID' AND ('I'. "" "UPDATE_DT"="H" UPDATE_DT' OR
"H"." UPDATE_DT ".<>
You may need to change the first condition to make sure that you select the correct subquery.
-edit
Not able to view a plan but you can invade the second join condition select and then the result of a subquery with a predicate according to your requirement. This should delay the or rating and leave only an equijoin (although rowsource return may be slightly larger than the opposite).
-Second edition, it did not work exactly when I tried it.
A hybrid of the previous two plans with a slight modification of how he was imitating the GOLD:
WITH h AS (SELECT / * + MATERIALIZE * / hi.message_id, hi.update_dt)
ROWNUM Clotilde
OF message_hist salvation)
SELECT i.MESSAGE_ID
i.UPDATE_DT
COALESCE(h.message_id,h2.message_id) message_id
, COALESCE (h.update_dt, h2.update_dt) update_dt
Clotilde COALESCE (h.rown, h2.rown)
Message FROM
LEFT JOIN: ON (i.message_id = h.message_id
AND i.update_dt = h.update_dt)
LEFT JOIN: h2 WE (DECODE(h.message_id,,i.message_id) = h2.message_id - only try this if previous join returned NULL
AND h2.update_dt<>
/
--------------------------------------------------------------------------------------------------------
| ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time |
--------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1. 66. 8 (0) | 00:00:01 |
| 1. TRANSFORMATION OF THE TEMPORARY TABLE. | | | | |
| 2. LOAD SELECT ACE | SYS_TEMP_0FD9D6605_28F27F | | | | |
| 3. COUNT | | | | | |
| 4. TABLE ACCESS FULL | MESSAGE_HIST | 150. 3300 | 2 (0) | 00:00:01 |
| 5. GLOBAL TRI | | 1. 66. | |
|* 6 | EXTERNAL RIGHT HASH JOIN | | 10497. 676K | 6 (0). 00:00:01 |
|* 7 | VIEW | | 150. 3300 | 2 (0) | 00:00:01 |
| 8. TABLE ACCESS FULL | SYS_TEMP_0FD9D6605_28F27F | 150. 3300 | 2 (0) | 00:00:01 |
|* 9 | OUTER HASH JOIN | | 328. 14432 | 4 (0) | 00:00:01 |
| 10. TABLE ACCESS FULL | MESSAGE | 200 | 4400 | 2 (0) | 00:00:01 |
| 11. VIEW | | 150. 3300 | 2 (0) | 00:00:01 |
| 12. TABLE ACCESS FULL | SYS_TEMP_0FD9D6605_28F27F | 150. 3300 | 2 (0) | 00:00:01 |
--------------------------------------------------------------------------------------------------------Information of predicates (identified by the operation identity card):
---------------------------------------------------6 - access("H2".") MESSAGE_ID "(+) = DECODE (TO_CHAR ('H'". "))" MESSAGE_ID"), NULL, 'I '. (("' MESSAGE_ID '))
7 - filter("H2".") UPDATE_DT "(+)<>
9 - access("I".") "UPDATE_DT" ="H" UPDATE_DT "(+) AND 'I'." "" ' MESSAGE_ID '="H" MESSAGE_ID "(+))"(This plan is another system if costs are not comparable)
-
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
-
That IS NULL is done by replacing the NOT EXISTS operator with an outer join?
DB version: 10 gr 2
An example of searchoracle.target.com
The query that contains a NOT EXISTS operator
is replaced by an equivalent outer join querySELECT M.ModulId, M.Modul FROM MODULE M WHERE NOT EXISTS ( SELECT PROJEKTMODUL.IdModul FROM PROJEKTMODUL WHERE M.ModulId = PROJEKTMODUL.IdModul AND PROJEKTMODUL.IdProjekt = 23 )
I do not understand whatselect distinct M.ModulId , M.Modul from MODULE M left outer join PROJEKTMODUL on M.ModulId = PROJEKTMODUL.IdModul and PROJEKTMODUL.IdProjekt = 23 where PROJEKTMODUL.IdProjekt is null
fact in the above rewritten query.PROJEKTMODUL.IdProjekt is null
He is to perform an anti-jointure. As far as I know Oracle (starting with version 10g - I thought that release 1) rewritten a Join Anti that resembles your second query of your request NOT EXISTS and NOT IN.
Look at the results of the query without the predicate IS NULL and see what records (from this set) must be selected to show the same results as the first query. Areas of interest match the predicate IS NULL.
-
Problems with Fade Out / Reload in State
I'm having the hardest time trying to figure this one... I have followed some good advice from these forums for this project in its current state, but cannot get it to work properly.
I use a "wheel" which is a custom/generic component (such as a popup) composed of all the buttons. Each click on the button it does two things:
1. it transitions to a new state that causes the just clicked the button to rotate to the top of the wheel
2. it fades into a new custom/generic component
This works really well.
The problem comes when I try to hide a newly added custom/generic component (via secquence action attached to a button in the new custom/generic component). For some reason any the area formerly covered by the custom/generic component is more clickable.
The other problem I foresee is if I can get the underlying custom/generic component buttons to work, I want to be sure that the "popups" (newly added in each new State custom/generic components) to reappear each time that the State is responsible.
I don't know there are a few really simple fix for what is beyond me. I have attached two screenshots of the 'wheel' and the 'wheel' covered by the 'popup '. I also published the project in its current state to one. SWF file if anyone is so inclined to give a try. If test you it, please note, I only worked on the first 4 buttons moving clockwise around the wheel.
Would appreciate any feedback!
Thank you.
DrewHi Drew,
I think I understand your problem and have something for you to try.
When you use a Fade out in a sequence of actions, the catalyst is animating the alpha (opacity) of the object from 100% to 0%. However, objects with 0% alpha still captures mouse clicks. The object must be invisible (which is different from 0% alpha!) to not capture the mouse clicks.
Unfortunately, there is no way to set an object to be invisible in a sequence of actions. What you can do is to encapsulate the popup itself in a custom component. Instead of using a sequence of actions to animate it, create two States: hidden and visible. Set the popup to be invisible (disable the eyeball in the layers panel) in the hidden state. Then set up your fade transitions. Now, just to make each button click "play transition to State" the popup component, ranging from the visible to the hidden state or vice versa.
-Adam
-
Satellite P300D 10V - problem with TV OUT
Hello!
I have a card ATI HD3650 in my Toshiba Satellite P300D 10V model and I can't use my TV out!
It does not work! How to start!I use a newer driver of origin! With the previous driver output TV not too worked!
Kind regards!
Hello
The laptop seems to support a 4pijn s-video port and HDMI port.
Which port you use to connect to the TV?You can use both and it only depends on the available on television port.
Choose the right channel on the TV and then use the FN + F5 key combination to switch to the TV out. -
Problems with the Out-of-Band updates
I am running Dell v2.0 OME. Everything works great including the updates via OMSA. However, the updates made via the iDRAC connections fail every time.
I could say I tried everything, but I thought someone might help me with troubleshooting whole again in case I missed something or did something wrong.
The connections of the DRAC live on a different subnet, but there is no firewall between these two networks. Only a router that routes traffic between the two. As I type this I came with some other ideas, but if you have something to offer that would be great.
Here is the error I get trying to deploy the updates.
Results:
Download the packages.
The call of method InstallFromUri to download packages to the iDRAC
Download package: BIOS_V7P04_WN64_2.2.3.EXE on iDRAC
Download the package has started successfully and the Job ID is JID_121890750543
The URI given to iDRAC to download it from: http://[serverip]:1278/install_packages/Packages/BIOS_V7P04_WN64_2.2.3.EXEChecking the status on the following tasks: JID_121890750543
The JOBID JID_121890750543 failed with the following message is displayed:
A package of updated network file transfer has failed.
MessageID: RED051Download error occurred.
Package BIOS_V7P04_WN64_2.2.3.EXE didn't upload on the target device. Update failed.
The task of software update failed.Thank you
Well the call with Dell has not helped, but eventually I was able to understand it. I learned that during an attempted search on a (executable) package for download, IIS returns a 404 error.
An example URL is http://[nameofserver]:1278/install_packages/Packages/SAS-RAID_Firmware_C3X7D_WN32_12.10.6-0001_a12.exe
I had to open the Web.config for the bulk of the site and adds the following snippey inside the
section.
The site's web.config file is located in C:\Program Files\Dell\SysMgt\Essentials\wwwroot\Essentials\.
Once the module was in place, I was able to navigate to any package and it would prompt me to download it. From there, I tested the updates again on the ESXi hosts and all is well again. I hope that this little information helps someone else!
Thanks again for everyone's help.
-
How to manage the update/insert in display with Outer Join object?
Hello
I have a problem in the treatment of update/insert in the original Version that contains two EOs with right outer join. The first EO values are inserted before and I want if second values EO already exists, it will update and if not a new record created.
Error when I commit after entering values is: ' entity line with null key is not found in SecondEO. "
What is the solution?
Thank you
Hello
Make sure that your view object, you have included the key attributes of the two entity objects.
Kind regards
Saif Khan.
-
Hi all
I need assistance with SQL FULL OUTER JOIN.
How to write with FULL OUTER JOIN, the query.
I tried like
I have 3 different queries.
Query q: SELECT emp_id LN.emp_id.
Sum (LN_amount) loan_amt
MY_LON_TAB LN
WHERE LN_amount > 20000
LN.emp_id GROUP;
Query b: SELECT PLN. EMP_ID emp_id,
Sum (PLAN_AMOUNT) plan_amt
FROM PLN MY_PLAN_TAB
where PLAN_AMOUNT <>0
GROUP BY PLN. EMP_ID;
Query C:
SELECT FLX. EMP_ID emp_id,
SUM (PRORATE_AMOUNT) PRORATE_AMT
OF MY_FLX_TAB FLX
WHERE PRORATE_AMOUNT <>0
FLX GROUP. EMP_ID;
Suppose that the different subquery above 3 a, b, c respectively. each subquery with emp_id and respective amount.
like a.emp_id, a.loan_amt
b.emp_id, b.plan_amt
c.emp_id, c.prorate_amt
I show all the empid with their amount respective.
schenario: If an account made, but not vice-versa b
and B have record, but not vice versa c
and a credit record but not vice versa c
first: I have external is associated with the A and B
Second: join external then complete the total outcome of (a & b) with c
but empid c just as empty.
My output is:
emp_id a.loan_amt, b.plan_amt c.prorate_amt
101 5000 null null
102 4500 null 2000
103 6700 null null
How to solve the foregoing to the ANSI (FULL OUTER JOIN) method.
Please suggest me.
Thanks in advance...
PKMHello
It is very difficult for anyone to say what you're doing wrong if they do not know what you are doing. Post your code FULL OUTER JOIN.
My best guess is:WITH a AS ( SELECT ... -- What you posted as query a ) , b AS ( SELECT ... -- What you posted as query b ) , c AS ( SELECT ... -- What you posted as query c ) SELECT COALESCE ( a.emp_id , b.emp_id , c.emp_id ) AS emp_id , ... -- whatever other columns you want FROM a FULL OUTER JOIN b ON b.emp_id = a.emp_id FULL OUTER JOIN c ON c.emp_id = COALESCE (a.emp_id, b.emp_id) ;
I hope that answers your question.
If not, post a small example (CREATE TABLE and INSERT statements) data for all tables and the results expected from these data (if not what you have already posted). -
Interactive reports on views with outer joins.
We tried to create an interactive report on a view with an outer join. It generated an error indicating that there is not a single column to identify the row. What APEX rule uses to identify the column that should be identify the line? Select statement should the correct column in the table that provides the extra lines to be one that is identified in the view?This is your link to the unique view of the record.
Delete the link; make your view preserved key (so you can use rowid) or identify a column to uniquely identify these lines for Apex.
This is done in the link column settings in the report attributes.
SW
-
Join with conditions of outer join statement
Hello
The following was extracted from the 11 GR 2 document guide performance, which I am not quite understand.
Can anyone provide some examples to clearly explain this. Thank you
For join instructions examples with outer join conditions, the table with the outer join operator must come after the other table in the condition in the join order. The optimizer does not consider join orders that violate this rule. Similarly, when a subquery was transformed into an antijoin or a semi-join, arrays of the subquery must come after these tables in the outer query to which they were connected or block in correlation. However, semijoins and antijoins of hash are override this order condition in certain circumstances
Maybe you are looking for
-
(This question was published only because I could not respond to existing similar questions without registering first.) Problem was apparently a Thunderbird randomly hanging after automatic update to 38.4 on Windows 7 Enterprise. The process of dropp
-
How to activate the touch screen in my laptop?
Hi everybodies... I have HP pavilion dv6-3020ed with all the drivers installed correctly... I try to activate the touch screen in win 7 64 bit - using the hp manual, but I found no proprietie tablet pc in my control panel? and TabTip.exe in C:\Progra
-
Size of array problem in Windows 7
Hi all I have a VI through the opening in a new laptop, it shows a few tables inadequate controls (with a table diferent size), however I can´t put it right. But when I'm doing an EXE of this VI and if I run the EXE in another computer, the façade se
-
change Outlook express to Microsoft outlook
I send my emails on outlook express I want to change to Microsoft, what do I do Gym1947