outer join query
Hi, here is the code to testcreate table dm_top (site varchar2(10),
area varchar2(10),
machine varchar2(10),
operation varchar2(10));
create table dm_mid (site varchar2(10),
area varchar2(10),
machine varchar2(10),
operation varchar2(10),
activity varchar2(10));
create table dm_tr(site varchar2(10),
area varchar2(10),
machine varchar2(10),
operation varchar2(10),
dm_tr_id number);
INSERT ordersinsert into dm_top
(site, area, machine, operation)
values
('site1','area1','machine1','oper1');
insert into dm_top
(site, area, machine, operation)
values
('site1','area1','machine1','oper2');
insert into dm_mid
(site, area, machine, operation, activity)
values
('site','area1','machine1','oper1','act1');
insert into dm_mid
(site, area, machine, operation, activity)
values
('site','area1','machine1','oper1','act2');
insert into dm_mid
(site, area, machine, operation, activity)
values
('site','area1','machine1','oper1','act3');
insert into dm_mid
(site, area, machine, operation, activity)
values
('site','area1','machine1','oper2','act1');
insert into dm_mid
(site, area, machine, operation, activity)
values
('site','area1','machine1','oper2','act2');
insert into dm_mid
(site, area, machine, operation, activity)
values
('site','area1','machine1','oper2','act3');
insert into dm_tr
(site, area, machine, operation, dm_tr_id)
values
('site','area1','machine1','oper1',9999);
and my desired output, always had to print even if there is no record in dm_trsite area1 machine1 oper1 act1 9999
site area1 machine1 oper1 act2 9999
site area1 machine1 oper1 act3 9999
site area1 machine1 oper2 act1
site area1 machine1 oper2 act2
site area1 machine1 oper2 act3
Thanks in advance.
Try this
select a.*,c.draft, b.dm_tr_id from dm_mid a,dm_tr b,dm_top c
where a.site = b.site (+) and
a.area = b.area (+) and
a.machine = b.machine (+) and
a.operation = b.operation (+) and
a.area = c.area (+) and
a.machine = c.machine(+) and
a.operation = c.operation(+)
order by 1,2,3,4,5
/
SITE AREA MACHINE OPERATION ACTIVITY D DM_TR_ID
---------- ---------- ---------- ---------- ---------- - ----------
site area1 machine1 oper1 act1 Y 9999
site area1 machine1 oper1 act2 Y 9999
site area1 machine1 oper1 act3 Y 9999
site area1 machine1 oper2 act1 N
site area1 machine1 oper2 act2 N
site area1 machine1 oper2 act3 N
6 rows selected.
Elapsed: 00:00:00.00
Kind regards
Prazy
Tags: Database
Similar Questions
-
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
-
Different Outer Join query result
Hi all
Under query gives the expected result
Select DECODE (FPOVR. PROFILE_OPTION_VALUE,
NULL, FPOVS. PROFILE_OPTION_VALUE, FPOVR. ZZ PROFILE_OPTION_VALUE)
OPS FND_PROFILE_OPTIONS, FND_PROFILE_OPTION_VALUES FPOVR,.
FND_PROFILE_OPTION_VALUES FPOVS where 1 = 1 and FPOVS. LEVEL_ID (+) = 10001
and FPOVS. LEVEL_VALUE (+) = 0
and FPOVS. PROFILE_OPTION_ID (+) IS FRENCH POLYNESIA. PROFILE_OPTION_ID
and FPOVR. (+) LEVEL_ID = 10003 and FPOVR. LEVEL_VALUE (+) = 21533
and FPOVR. PROFILE_OPTION_ID (+) IS FRENCH POLYNESIA. PROFILE_OPTION_ID
and fpo.profile_option_name = 'GL_SET_OF_BKS_ID. '
But the following query does not give the expected result.
Select DECODE (FPOVR. PROFILE_OPTION_VALUE,
NULL, FPOVS. PROFILE_OPTION_VALUE, FPOVR. ZZ PROFILE_OPTION_VALUE)
OPS FND_PROFILE_OPTIONS, FND_PROFILE_OPTION_VALUES FPOVR,.
FND_PROFILE_OPTION_VALUES FPOVS where 1 = 1 and FPOVS. LEVEL_ID (+) = 10001
and FPOVS. LEVEL_VALUE (+) = 0
and FPOVS. PROFILE_OPTION_ID (+) IS FRENCH POLYNESIA. PROFILE_OPTION_ID
and FPOVR. (+) LEVEL_ID = 10003 and FPOVR. LEVEL_VALUE = 21533
and FPOVR. PROFILE_OPTION_ID (+) IS FRENCH POLYNESIA. PROFILE_OPTION_ID
and fpo.profile_option_name = 'GL_SET_OF_BKS_ID. '
Difference between them is a join with external FPOVR. LEVEL_VALUE and hard coded value. Why these query above return different results even if the outer join is made with hard coded in value?
Thank you
SKSK says:
Hi allUnder query gives the expected result
Select DECODE (FPOVR. PROFILE_OPTION_VALUE,
NULL, FPOVS. PROFILE_OPTION_VALUE, FPOVR. ZZ PROFILE_OPTION_VALUE)
OPS FND_PROFILE_OPTIONS, FND_PROFILE_OPTION_VALUES FPOVR,.
FND_PROFILE_OPTION_VALUES FPOVS where 1 = 1 and FPOVS. LEVEL_ID (+) = 10001
and FPOVS. LEVEL_VALUE (+) = 0
and FPOVS. PROFILE_OPTION_ID (+) IS FRENCH POLYNESIA. PROFILE_OPTION_ID
and FPOVR. (+) LEVEL_ID = 10003 and FPOVR. LEVEL_VALUE (+) = 21533
and FPOVR. PROFILE_OPTION_ID (+) IS FRENCH POLYNESIA. PROFILE_OPTION_ID
and fpo.profile_option_name = 'GL_SET_OF_BKS_ID. 'But the following query does not give the expected result.
Select DECODE (FPOVR. PROFILE_OPTION_VALUE,
NULL, FPOVS. PROFILE_OPTION_VALUE, FPOVR. ZZ PROFILE_OPTION_VALUE)
OPS FND_PROFILE_OPTIONS, FND_PROFILE_OPTION_VALUES FPOVR,.
FND_PROFILE_OPTION_VALUES FPOVS where 1 = 1 and FPOVS. LEVEL_ID (+) = 10001
and FPOVS. LEVEL_VALUE (+) = 0
and FPOVS. PROFILE_OPTION_ID (+) IS FRENCH POLYNESIA. PROFILE_OPTION_ID
and FPOVR. (+) LEVEL_ID = 10003 and FPOVR. LEVEL_VALUE = 21533
and FPOVR. PROFILE_OPTION_ID (+) IS FRENCH POLYNESIA. PROFILE_OPTION_ID
and fpo.profile_option_name = 'GL_SET_OF_BKS_ID. 'Difference between them is a join with external FPOVR. LEVEL_VALUE and hard coded value.
In fact, the difference is that the condition relating to FPOVR. LEVEL_VALUE to 21533 is part of the outer join condition in the first query, but it is not in the second query.
Why these query above return different results even if the outer join is made with hard coded in value?
When you say
FPOVR.LEVEL_VALUE(+) = 21533
(with a sign +) only the lines of fpovr with level_value = 21533 will join the other table. If there is no such line in fpovr, then a row of output will be generatedd for each row in the other table anyway.
When you sayFPOVR.LEVEL_VALUE = 21533
(without a sign +) then the outer join is made using the other conditions, which may result in some lines of the other table who appear in the result set with NULL in places where the values of fpovr would normally appear. Then when the join is complete, the condition is applied, and all these lines with the NULL value instead of fpovr.level_value are deleted because they do not meet the condition "FPOVR. LEVEL_VALUE = 21533 ". The effect is identical to an inner join.
When you use the old rating of outer join (i.e. with signs +), if any condition involving the fpovr table has a + sign, and then all of the conditions involving table fpovr must have a + sign, otherwise the result will be the same if none of the conditions were a sign +.
-
need help for an outer join query
Hi friends...
I have oracle 10g...
I have a question which involve is joining three tables...
the query is as follows:
in my front end application has some delete operations that removes specific data of the IPOADM_BATCH. MKT_SPEC_UV1 due to which the above query is nor fetch all rows.SELECT DISTINCT MU.MKT_ID "PAR ID", MU.MKT_ID "ROOT ID", MSU.SPEC_ID "ID", SU.SPEC_DESC "DESC", SU.SPEC_CD "SPEC CD" FROM IPOADM_BATCH.MKT_UV1 MU, IPOADM_BATCH.MKT_SPEC_UV1 MSU, IPOADM_BATCH.SPEC_UV1 SU WHERE MSU.MKT_ID = MU.MKT_ID AND MSU.SPEC_ID = SU.SPEC_ID AND SU.SPEC_GRP_OR_CMPSTN_CD = 'C';
the relationship between the tables is clearly from the above query...
I have the data in IPOADM_BATCH. MKT_UV1 and IPOADM_BATCH. Table of SPEC_UV1 after the delete operation
now, I want the query above to retrieve data from IPOADM_BATCH. MKT_UV1 with small changes to the above query even if there is no data in IPOADM_BATCH. MKT_SPEC_UV1.
I thought that if I use an outer join I can get it, but here I have to join three tables-join condition is based on the table that doesn't have a data...
so please help me guys how can I change the query to get my desired out put...Hello
There are several different things you could mean by it.
Here's how to join the tables to get one of them:
SELECT DISTINCT mu.mkt_id "PAR ID", mu.mkt_id "ROOT ID", msu.spec_id "ID", su.spec_desc "DESC", su.spec_cd "SPEC CD" FROM ipoadm_batch.mkt_uv1 mu LEFT OUTER JOIN ipoadm_batch.mkt_spec_uv1 msu ON msu.mkt_id = mu.mkt_id LEFT OUTER JOIN ipoadm_batch.spec_uv1 su ON msu.spec_id = su.spec_id AND su.spec_grp_or_cmpstn_cd = 'C' ;
If it does not matter what it is that you want, and then after a small example of data (CREATE TABLE and INSERT, only relevant columns instructions) for all the tables and the results desired from these data.
Highlight a few places where the above querry is the production of incorrect results of your sample data and explains how to get the correct results in these places. -
OUTER JOIN query returns the results of JOIN IN-HOUSE 11.2.0.1.0
I'm data transfer in 11.2.01.0 (Windows XP 32-bit) and I wanted to compare the sizes of table with the same Table name in two different patterns, ML and SILENT, with a FULL OUTER JOIN (to account for all the tables and NULL values in a diagram).
The scheme of ML has 176 tables: schema TUT a 133 tables. The use of a standard INNER JOIN gives 131 paintings.
I get precisely the results with a FULL OUTER JOIN I get with an INTERNAL JOIN (not the same NULL values so I know they exist).
This happens in SQL-Plus, SQL_Developer and using Oracle Wire pilot of Data_Direct.
Here is the code:
Login: SYS as SYSDBA or SYSTEM (same results for either)
SELECT M.TABLE_NAME, M.NUM_ROWS, T.TABLE_NAME, T.NUM_ROWS
OF SYS. ALL_TABLES M FULL OUTER JOIN SYS. ALL_TABLES T ON M.TABLE_NAME = T.TABLE_NAME
WHERE
M.OWNER = 'ML' AND
T.OWNER = 'TUT';
Produce the same results with LEFT OUTER joins and RIGHT OUTER joins in ASI and Oracle (+) syntax.
Any thoughts?Hello
If you read what I posted, forget it. MScallion (below) gave the correct answerr.
If conditions such as
owner = 'ML'
in the WHERE clause, and then they will reject the rows of the result set formed by the join condition.
The inner join returns only 131 lines where the two 'paintings' have the same table_names.
The outer joins return multiple lines (133, 176 or 178) before the place WHERE the provision is applied , but the WHERE clause eliminates all lines except the 131 found by the inner join.Published by: Frank Kulash, July 10, 2010 14:23
-
Left outer join query and check the status
Hello
I have two tables as tables below
table_1
MI_ACC_IDENTIFIER CHARGE_START_DATE CHARGE_END_DATE PBA_INT_AMT 2000000000 01 SEP-05 00.00.00 29 SEP-05 00.00.00 0.26 2000000000 30 SEP-05 00.00.00 31 OCTOBER 05 00.00.00 1.92 2000000000 1 NOVEMBER 05 00.00.00 NOVEMBER 30 05 00.00.00 0.34 2000000000 1 AUGUST 06 00.00.00 31 AUGUST 06 00.00.00 0.47 2000000000 31 MARCH 06 00.00.00 27 APRIL 06 00.00.00 0.34 2000000000 30 DECEMBER 05 00.00.00 31 JANUARY 06 00.00.00 1.92 2000000000 1 MARCH 05 00.00.00 31 MARCH 05 00.00.00 0.26 Table_2
MI_ACC_IDENTIFIER CHARGE_START_DATE CHARGE_END_DATE TOT_INT_AMT_OVER_25P 2000000000 30 SEP-05 00.00.00 31 OCTOBER 05 00.00.00 0 2000000000 1 NOVEMBER 05 00.00.00 NOVEMBER 30 05 00.00.00 0.81756 2000000000 1 DECEMBER 05 00.00.00 29 DECEMBER 05 00.00.00 0.64724 2000000000 30 DECEMBER 05 00.00.00 31 JANUARY 06 00.00.00 5.51555 Power required:
MI_ACC_IDENTIFIER CHARGE_START_DATE CHARGE_END_DATE NVL(B.PBA_INT_AMT,0) TOT_INT_AMT_OVER_25P 2000000000 1 NOVEMBER 05 00.00.00 NOVEMBER 30 05 00.00.00 0.34 0.81756 2000000000 30 DECEMBER 05 00.00.00 31 JANUARY 06 00.00.00 1.92 5.51555 2000000000 1 DECEMBER 05 00.00.00 29 DECEMBER 05 00.00.00 0 0.64724 I have to check if TOT_INT_AMT_OVER_25P > B.PBA_INT_AMT and also required to display if there is no matching record in table_1 and exist in table_2 then display as well
Queries for the table:
CREATE TABLE 'TABLE_1 '.
(
ACTIVATE THE "MI_ACC_IDENTIFIER" NUMBER (10,0) NOT NULL,
DATE OF THE "CHARGE_START_DATE."
DATE OF THE "CHARGE_END_DATE."
NUMBER (15.2) "PBA_INT_AMT".
);
Insert into TABLE_1 (MI_ACC_IDENTIFIER, CHARGE_START_DATE, CHARGE_END_DATE, PBA_INT_AMT) values (2000000000, to_date ('01 - SEP - 05 00.00.00','DD-MON-RR HH24.MI.)) SS'), to_date (29-SEP-05 00.00.00','DD-MON-RR HH24.MI.) SS'), 0.26);
Insert into TABLE_1 (MI_ACC_IDENTIFIER, CHARGE_START_DATE, CHARGE_END_DATE, PBA_INT_AMT) values (2000000000, to_date (30-OCT-05 00.00.00','DD-MON-RR HH24.MI.)) SS'), to_date (31 October 05 00.00.00','DD-MON-RR HH24.MI.) SS'), 1.92);
Insert into TABLE_1 (MI_ACC_IDENTIFIER, CHARGE_START_DATE, CHARGE_END_DATE, PBA_INT_AMT) values (2000000000, to_date (1 November 05 00.00.00','DD-MON-RR HH24.MI.)) To_date SS'), (30 November 05 00.00.00','DD-MON-RR HH24.MI.) SS'), 0.34).
Insert into TABLE_1 (MI_ACC_IDENTIFIER, CHARGE_START_DATE, CHARGE_END_DATE, PBA_INT_AMT) values (2000000000, to_date (1 August 06 00.00.00','DD-MON-RR HH24.MI.)) SS'), to_date (31 August 06 00.00.00','DD-MON-RR HH24.MI.) SS'), 0.47);
Insert into TABLE_1 (MI_ACC_IDENTIFIER, CHARGE_START_DATE, CHARGE_END_DATE, PBA_INT_AMT) values (2000000000, to_date (31 March 06 00.00.00','DD-MON-RR HH24.MI.)) To_date SS'), (27 April 06 00.00.00','DD-MON-RR HH24.MI.) SS'), 0.34).
Insert into TABLE_1 (MI_ACC_IDENTIFIER, CHARGE_START_DATE, CHARGE_END_DATE, PBA_INT_AMT) values (2000000000, to_date (30 December 05 00.00.00','DD-MON-RR HH24.MI.)) To_date SS'), (31 January 06 00.00.00','DD-MON-RR HH24.MI.) SS'), 1.92);
Insert into TABLE_1 (MI_ACC_IDENTIFIER, CHARGE_START_DATE, CHARGE_END_DATE, PBA_INT_AMT) values (2000000000, to_date (1 March 05 00.00.00','DD-MON-RR HH24.MI.)) SS'), to_date (31 March 05 00.00.00','DD-MON-RR HH24.MI.) SS'), 0.26);
CREATE TABLE 'TABLE_2.
(
ACTIVATE THE "MI_ACC_IDENTIFIER" NUMBER (10,0) NOT NULL,
DATE OF THE "CHARGE_START_DATE."
DATE OF THE "CHARGE_END_DATE."
"TOT_INT_AMT_OVER_25P" NUMBER (15.5)
);
Insert in TABLE_2 (MI_ACC_IDENTIFIER, CHARGE_START_DATE, CHARGE_END_DATE, TOT_INT_AMT_OVER_25P) values (2000000000, to_date (30-OCT-05 00.00.00','DD-MON-RR HH24.MI.)) SS'), to_date (31 October 05 00.00.00','DD-MON-RR HH24.MI.) SS'), 0);
Insert in TABLE_2 (MI_ACC_IDENTIFIER, CHARGE_START_DATE, CHARGE_END_DATE, TOT_INT_AMT_OVER_25P) values (2000000000, to_date (1 November 05 00.00.00','DD-MON-RR HH24.MI.)) To_date SS'), (30 November 05 00.00.00','DD-MON-RR HH24.MI.) SS'), 0.81756);
Insert in TABLE_2 (MI_ACC_IDENTIFIER, CHARGE_START_DATE, CHARGE_END_DATE, TOT_INT_AMT_OVER_25P) values (2000000000, to_date (1 December 05 00.00.00','DD-MON-RR HH24.MI.)) SS'), to_date (29 December 05 00.00.00','DD-MON-RR HH24.MI.) SS'), 0.64724);
Insert in TABLE_2 (MI_ACC_IDENTIFIER, CHARGE_START_DATE, CHARGE_END_DATE, TOT_INT_AMT_OVER_25P) values (2000000000, to_date (30 December 05 00.00.00','DD-MON-RR HH24.MI.)) To_date SS'), (31 January 06 00.00.00','DD-MON-RR HH24.MI.) SS'), 5.51555);
Query, I used:
SELECT A.MI_ACC_IDENTIFIER, A.CHARGE_START_DATE, A.CHARGE_END_DATE, NVL (B.PBA_INT_AMT, 0), a.TOT_INT_AMT_OVER_25P OF TABLE_2 A, B FROM TABLE_1 WHERE A.MI_ACC_IDENTIFIER = B.MI_ACC_IDENTIFIER (+) AND A.CHARGE_START_DATE = B.CHARGE_START_DATE (+) AND A.CHARGE_END_DATE = B.CHARGE_END_DATE (+) and A.TOT_INT_AMT_OVER_25P > B.PBA_INT_AMT (+); I have been using the syntax of ANSI join for some time. They are readable and code looks more elegant. A reason do not want to use it?
I don't care
SQL> select t2.mi_acc_identifier 2 , t2.charge_start_date 3 , t2.charge_end_date 4 , nvl(t1.pba_int_amt, 0) pba_int_amt 5 , t2.tot_int_amt_over_25p 6 from table_1 t1 7 , table_2 t2 8 where t1.mi_acc_identifier (+)= t2.mi_acc_identifier 9 and t1.charge_start_date (+)= t2.charge_start_date 10 and t1.charge_end_date (+)= t2.charge_end_date 11 and (t1.pba_int_amt < t2.tot_int_amt_over_25p or t1.mi_acc_identifier is null); MI_ACC_IDENTIFIER CHARGE_ST CHARGE_EN PBA_INT_AMT TOT_INT_AMT_OVER_25P ----------------- --------- --------- ----------- -------------------- 2000000000 01-NOV-05 30-NOV-05 .34 .81756 2000000000 30-DEC-05 31-JAN-06 1.92 5.51555 2000000000 01-DEC-05 29-DEC-05 0 .64724 SQL>
-
Outer join does not not as expected left
Hi all
I have it here are three tables with values. Mentioned the under outer join query does not and behave like the inner query.
CREATE TABLE RET_FUND_FEE
(
NPTF VARCHAR2 (8 CHAR),
TPART VARCHAR2 (4 CHAR)
);
CREATE TABLE PART_PTF
(
Mf_Id VARCHAR2 (6 CHAR) NOT NULL,
TPARTS VARCHAR2 (4 CHAR) NOT NULL
);
CREATE TABLE TFC_FUNDS
(
NPTF VARCHAR2 (8 CHAR) NOT NULL,
MULTIFONDS_ID VARCHAR2 (6 CHAR)
);
INSERT INTO RET_FUND_FEE VALUES('111','A');
INSERT INTO RET_FUND_FEE VALUES('111','D');
INSERT INTO RET_FUND_FEE VALUES('111','E');
INSERT INTO PART_PTF VALUES ('MF1', 'A');
INSERT INTO PART_PTF VALUES ('MF1', 'B');
INSERT INTO PART_PTF VALUES('MF1','C');
INSERT INTO TFC_FUNDS VALUES('111','MF1');
INSERT INTO TFC_FUNDS VALUES('111','MF1');
INSERT INTO TFC_FUNDS VALUES('111','MF1');
SELECT A.TPART, B.TPARTS, A.NPTF, B.Mf_Id, C.MULTIFONDS_ID, C.NPTF
OF RET_FUND_FEE A, PART_PTF B, TFC_FUNDS C
WHERE A.NPTF = C.NPTF
AND C.MULTIFONDS_ID = B.Mf_Id
AND A.TPART = B.TPARTS (+)
AND C.MULTIFONDS_ID = 'MF1 '.
AND C.NPTF = '111'
Here, I expect all records in the RET_FUND_FEE table that I am using outer join.
But I'm only corresponding chronogram RET_FUND_FEE, PART_PTF as an inner join. Can you get it someone please let me know what lack us.
Is my version of oracle 11g
SELECT
A.TPART, B.TPARTS, A.NPTF, B.Mf_Id, C.MULTIFONDS_ID, C.NPTF
Of
PART_PTF B
Join
C TFC_FUNDS
on (C.MULTIFONDS_ID = B.Mf_Id
AND C.MULTIFONDS_ID = 'MF1 '.
AND C.NPTF = '111'
)
right outer join
RET_FUND_FEE HAS
on (A.TPART = B.TPARTS
and A.NPTF = C.NPTF) - added as correction
TPART TPARTS NPTF MF_ID MULTIFONDS_ID NPTF A A 111 MF1 MF1 111 A A 111 MF1 MF1 111 A A 111 MF1 MF1 111 E - 111 - - - D - 111 - - - or
SELECT A.TPART, d.TPARTS, A.NPTF, d.Mf_Id, d.MULTIFONDS_ID, d.NPTF
OF RET_FUND_FEE HAS
, (
Select
*
PART_PTF b, TFC_FUNDS C
where B.Mf_Id = C.MULTIFONDS_ID
AND C.MULTIFONDS_ID = 'MF1 '.
AND C.NPTF = '111'
) d
WHERE A.TPART = D.TPARTS (+)
and A.NPTF = D.NPTF (+) - added as a correction
Sorry had to correct the syntax oracle solution.
The first one was bad because it would return also B lines that have no match in C.
Sorry a correction more on these two approaches, missed the second predicate.
-
Oracle 10g
I have three below queries that use the outer join syntax.
All three queries return exactly the same results
(a)
(b)SELECT TA.ID TA , TB.ID TB FROM TA , TB WHERE TA.ID = TB.ID(+);
(c)SELECT TA.ID TA , TB.ID TB FROM TA , TB WHERE TB.ID(+) = TA.ID;
I have the right call outer join query because the (+) sign is located on the right and outer join query (b) left because the (+) sign is on the left?SELECT TA.ID TA , TB.ID TB FROM TA LEFT OUTER JOIN TB ON TA.ID = TB.ID;
Or is the left join or right determined by the join columns specified in the order select it?
Create the Script
BenCREATE TABLE TA ( "ID" NUMBER ); CREATE TABLE TB ( "ID" NUMBER ); INSERT INTO TA (ID) VALUES ('1'); INSERT INTO TA (ID) VALUES ('2'); INSERT INTO TA (ID) VALUES ('3'); INSERT INTO TB (ID) VALUES ('1'); INSERT INTO TB (ID) VALUES ('2'); INSERT INTO TB (ID) VALUES ('4');
Published by: benton on August 15, 2012 08:16Hi, Ben.
Benton says:
... So is it correct to say that the left or right refers to which side the null values will be displayed?Lol it is incorrect to say that the old syntax outer join (using the sign +) is either a left - or a right outer join.
... So I need to have the order of the columns in the correct SELECTION so that there is no likelihood of confusion over which side will display NULL values. If I place the columns A and B in the wrong order, that is to say B then a I'll lend to confusion about what will be returned with respect whether left or right.
No, do not hesitate to organize columns in the select in any way will help your users the most. What is happening in the FROM and WHERE clause, in particular the order in which the tables happens to appear, may not have something to do with the order of the columns in the output.
Many readers are more comfotable with having NULL columns at the end of a line of output, or at least not at the beginning, so maybe it's one of the reasons for ta.id first in your example. Rearrange the columns in the game any way more than makes sense for people who will look at them. -
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.
-
outer join on the aggregate query
This is probably a relatively simple matter, as long as I explain it well enough:
I have two tables:
categorycodes and properties
categorycodes is a lookup table.
both tables have a catcode field which is a char (1) that contains matching data (only the numbers 1 to 6)
CREATE
TABLE CATEGORYCODES
(
CATCODE CHAR (1 BYTE) NOT NULL,
DESCRIPTION VARCHAR2 (25 BYTE) NOT NULL,
CONSTRAINT CATEGORYCODES_PK PRIMARY KEY (CATCODE) ALLOW
)
catCode
1
2
3
4
5
6
The properties table has approximately 600 000 records. The properties table also has a field named parcelno which is a tank (9). It contains a string of figures and numbers only.
What I would like is:
catCode, count (*)
1 580
2 300
3 3000
4 235
5 0
6 80
I limited the results of the query to make sure it was a game that would not all catcodes in it. I have trouble to get the one with zero to display. I know that this has to do with how I do the join, but I don't know what.
It is a sample of what I've tried:
Select i.
Of
(select catcode, count (*)
property p
where substr (parcelno, 1, 3) = ' 871 "
Catcode group) i
outer join right categorycodes cc
We i.catcode = cc.catcode;
I'm not worried about the situations where catcode is null in the properties. Parcelno cannot be null.
Hello
Looks like your query should work; except that you won't COUNT (*); That would make each issue at least 1. COUNT (*) means that count the total number of lines, no matter what is on them, so he'll see the line with just the catcode of the lookup table that matches nothing and which count as 1. You want to count the number of rows in the table of properties, so expect a column of the properties that cannot be NULL.
Here is a slightly different way
SELECT c.catcode
EARL of (p.catcode) AS cnt
OF categorycodes c
P ON p.catcode = c.catcode LEFT OUTER JOIN properties
AND SUBSTR (p.parcelno
1
3
) = ' 871 "
;
If the condition about 871' ' part of the join condition, then you don't need a subquery.
.
I hope that answers your question.
If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and also publish outcomes from these data.
Point where the above statement is erroneous results, and explain, using specific examples, how you get the right result of data provided in these places.Always say what version of Oracle you are using (for example, 11.2.0.2.0).
See the FAQ forum: https://forums.oracle.com/message/9362002
-
How do the query select outer join to a report of the APEX
Hi all
I'm Ann.
I have a select statement that is used to calculate statistics for a month (October 2012 in this example)
Select ph.phase_number
sum ((case
WHEN ph.date_finished IS NULL or ph.date_finished > last_day (TO_DATE (' ' Oct 2012 ', ' MY YYYY' "))
THEN last_day (TO_DATE (' ' Oct 2012 ', ' MY YYYY' "))
Of OTHER ph.date_finished
END)
(-ph.date_started + 1) / count (def.def_id) as avg_days
Ph phase_membership
inner join court_engagement this on ph.mpm_eng_id = ce.engagement_id
join in-house defendant def on ce.defendant_id = def.def_id
where def.active = 1
and ph.date_started < = last_day (TO_DATE (' ' Oct 2012 ', ' MY YYYY' "))
and ph.active = 1
and UPPER (ce.court_name) LIKE '% '.
Rollup Group (phase_number)
;
The result is as below
Phase_Number AVG_DAYS
Phase One 8.6666666666666667
Phase two 14.6
Phase three 12
11.4615365
I have another list of selection mainly the list of months between two date value.
Select to_char (which_month, 'LUN YYYY') as display_month
de)
Select add_months (to_date (' ' August 2012 ', ' MY YYYY' "), rownum-1) which_month
of object
where
rownum < = months_between (to_date (' ' Oct 2012 ', ' MY YYYY' "), add_months (to_date (' ' August 2012", "MY YYYY"), - 1))
order of which_month)
The query result is as below
DISPLAY_MONTH
AUGUST 2012
SEP 2012
OCT 2012
Is it possible I can join these two select statement above to generate a comparable result:
Days of month Phase number Avg
August 2012 Phase One 8.666
Sep 2012 Phase One 7.66
Oct 2012 Phase One 5,66
August 2012 Phase two 8.666
Sep 2012 Phase two 7.66
Oct 2012 Phase two 5,66
August 2012 Phase three 8.666
Sep 2012 Phase three 7.66
Oct 2012 Phase three 5,66
Or
Days of month Phase number Avg
August 2012 Phase One 8.666
August 2012 Phase two 7.66
August 2012 Phase three 5,66
Sep 2012 Phase One 8.666
Sep 2012 Phase two 7.66
Sep 2012 Phase three 5,66
Oct 2012 Phase One 8.666
Oct 2012 Phase two 7.66
Oct 2012 Phase three 5,66
And it can be controlled by Phase number or month.
My other colleague suggested I should use a left outer join, but after having tried many ways, I'm still stuck.
I tried select is
Select a.display_month, b.* in)
Select to_char (which_month, 'LUN YYYY') as display_month
de)
Select add_months (to_date (' ' August 2012 ', ' MY YYYY' "), rownum-1) which_month
of object
where
rownum < = months_between (to_date (' ' Oct 2012 ', ' MY YYYY' "), add_months (to_date (' ' August 2012", "MY YYYY"), - 1))
order which_month)) a left outer join
(Select to_char (ph.date_finished, 'MY YYYY') as join_month, ph.phase_number)
sum ((case
WHEN ph.date_finished IS NULL or ph.date_finished > last_day (TO_DATE (a.display_month, 'MY YYYY'))
THEN last_day (TO_DATE (a.display_month, 'MY YYYY'))
Of OTHER ph.date_finished
END)
(-ph.date_started + 1) / count (def.def_id) as avg_days
Ph phase_membership
inner join court_engagement this on ph.mpm_eng_id = ce.engagement_id
join in-house defendant def on ce.defendant_id = def.def_id
where def.active = 1
and ph.date_started < = last_day (TO_DATE (a.display_month, 'MY YYYY'))
and ph.active = 1
and UPPER (ce.court_name) LIKE '% '.
To_char (ph.date_finished, 'MY YYYY'), group (phase_number) rollup) b
On a.display_month = b.join_month
but then I get an error
SQL error: ORA-00904: "A." "" DISPLAY_MONTH ": invalid identifier
I need to view a report on the APEX with option for people to download at least format CSV.
Already 1 inteactive report in the page, so I don't think adds another interactive report without using the iframe trick.
If any of you have any ideas, please help.
Thank you very much.
AnnHello Ann,.
Frank has done a very good job. I am also impressed.
Is in regard to your correction to his question, the problem is on this replacement you did
last_day(TO_DATE(am.which_month,'MON YYYY'))
AM.which_month is already a date type, and you don't need to convert it to this day.
Here is the correct way:last_day(am.which_month)
There are also sometimes with the data you've posted have no line for this month. So I also added a function NVL to display 0 under avg_days for these cases.
Here is my corrected query:
DEFINE startmonth = "Aug 2012"; DEFINE endmonth = "Oct 2012"; WITH all_months AS ( SELECT ADD_MONTHS(to_date('&startmonth','MON YYYY'), ROWNUM-1) AS which_month , ADD_MONTHS(to_date('&startmonth','MON YYYY'), ROWNUM ) AS next_month from all_objects where rownum <= months_between(to_date('&endmonth','MON YYYY'), add_months(to_date('&startmonth','MON YYYY'), -1)) ) SELECT TO_CHAR (am.which_month, 'Mon YYYY') AS month , ph.phase_number , NVL(sum ( (CASE WHEN ph.date_finished IS NULL OR ph.date_finished > last_day(am.which_month) THEN last_day(am.which_month) ELSE ph.date_finished END ) - ph.date_started + 1 ) / count(def.def_id), 0) as avg_days FROM all_months am LEFT OUTER JOIN a_phase_membership ph PARTITION BY (ph.phase_number) ON am.which_month <= ph.date_started AND am.next_month > ph.date_started AND ph.date_started <= last_day(am.which_month) -- May not be needed AND ph.active = 1 LEFT OUTER JOIN a_engagement ce ON ph.mpm_eng_id = ce.engagement_id AND ce.court_name IS NOT NULL -- or something involving LIKE LEFT OUTER join a_defendant def ON ce.defendant_id = def.def_id AND def.active = 1 GROUP BY ROLLUP(phase_number, am.which_month) ORDER BY am.which_month , ph.phase_number ; The output is: MONTH PHASE_NUMBER AVG_DAYS -------- -------------------- ---------- Aug 2012 PHASE ONE 0 Aug 2012 PHASE THREE 0 Aug 2012 PHASE TWO 0 Sep 2012 PHASE ONE 12 Sep 2012 PHASE THREE 1 Sep 2012 PHASE TWO 9 Oct 2012 PHASE ONE 8 Oct 2012 PHASE THREE 0 Oct 2012 PHASE TWO 14 PHASE ONE 11 PHASE THREE 1 PHASE TWO 11.5 9.71428571
I don't know if that's really what you want. In the case check it and let me know.
Kind regards.
Al -
How create/update files when the original Version is based on a query of outer join?
Hi gurus,
I created a custom page where I use a table-style area where I question my VO records, based on a query of outer join. This query contains my table looks, where I would like to insert/update records, and joined the table of standard elements, which is external with my custom table.
When I now question my files in the t, I have a record for each record in the table section, which is ok, but when I 'Refresh' some fields of my custom table and attempt to commit, I get the message "unable to complete the transaction on record. Cause: The record has been deleted by another user. "Action: cancel the transaction and re - query records to get new data.
The reason why because a record is to be inserted rather than updating because in fact there is not yet in my custom table.
The reason why I'm using the outer join, is because I don't want the user to create a record for each item one by one.
There is no work around for this?
Thanks in advance!
BR
GuyHello
You can try this.In your EntityImpl.java to extend OAPlsqlEntityImpl.
Override the updateRow() method and coding your insert statement to insert into a table custom here.
Don't forget, you must ignore the lines for which your custom table columns are null-Idris
-
outer join on query with the GOLD clause
Hi all, I have a problem outerjoining a clause or a request with
Here's my data
as you can see I am attaching the table 1 and table 2. I join with txt1, if txt1 is null, then join by txt2, if null, then reach by txt3 and so on.WITH table1 AS ( SELECT 'test' txt1, 'pak' txt2, 'ced' txt3, 'su' txt4 FROM dual UNION ALL SELECT null txt1, 'pak' txt2, 'ced2' txt3, 'su2' txt4 FROM dual UNION ALL SELECT null txt1, NULL txt2, 'ced3' txt3, 'su3' txt4 FROM dual UNION ALL SELECT null txt1, NULL txt2, null txt3, 'su3' txt4 FROM dual UNION ALL SELECT 'text5' txt1, NULL txt2, null txt3, 'su3' txt4 FROM dual UNION ALL SELECT null txt1, NULL txt2, null txt3, null txt4 FROM dual ) ,table2 AS ( SELECT 111 pid, 'test' txt1, 'pak4' txt2, 'ced' txt3, 'su' txt4 FROM dual UNION ALL SELECT 222 pid, 'test1' txt1, 'pak' txt2, 'ced2' txt3, 'su2' txt4 FROM dual UNION ALL SELECT 333 pid, 'test2' txt1, 'pak3' txt2, 'ced3' txt3, 'su4' txt4 FROM dual UNION ALL SELECT 444 pid, 'test2' txt1, 'pak3' txt2, 'ced4' txt3, 'su3' txt4 FROM dual ) SELECT b.pid, a.* from table1 a, table2 b WHERE (a.txt1 = b.txt1 OR a.txt1 IS NULL AND a.txt2=b.txt2 OR Nvl(a.txt2, a.txt1) IS NULL AND a.txt3 = b.txt3 OR Nvl(a.txt2, a.txt1) IS NULL AND a.txt3 IS NULL AND a.txt4 = b.txt4 )
the above produces this output code
This output is partially correct. only 4 lines were in display and two has been left outPID TXT1 TXT2 TXT3 TXT4 === ==== === ==== ==== 111 test pak ced su 222 pak ced2 su2 333 ced3 su3 444 su3
I tried to use the outer join, but oracle will complain that I can't use outerjoin with the GOLD clause.SELECT 'text5' txt1, NULL txt2, null txt3, 'su3' txt4 FROM dual UNION ALL SELECT null txt1, NULL txt2, null txt3, null txt4 FROM dual
can someone modify my query to display the output below?
PID TXT1 TXT2 TXT3 TXT4 === ==== === ==== ==== 111 test pak ced su 222 pak ced2 su2 333 ced3 su3 444 su3 NULL NULL NULL NULL NULL test5
Not sure you can do it with the style of the Oracle of outer joins, but open ANSI style joins is simple, in fact exactly as you had it.
SQL> set null null; SQL> WITH table1 AS ( 2 SELECT 'test' txt1, 'pak' txt2, 'ced' txt3, 'su' txt4 FROM dual UNION ALL 3 SELECT null txt1, 'pak' txt2, 'ced2' txt3, 'su2' txt4 FROM dual UNION ALL 4 SELECT null txt1, NULL txt2, 'ced3' txt3, 'su3' txt4 FROM dual UNION ALL 5 SELECT null txt1, NULL txt2, null txt3, 'su3' txt4 FROM dual UNION ALL 6 SELECT 'text5' txt1, NULL txt2, null txt3, 'su3' txt4 FROM dual UNION ALL 7 SELECT null txt1, NULL txt2, null txt3, null txt4 FROM dual), 8 table2 AS ( 9 SELECT 111 pid, 'test' txt1, 'pak4' txt2, 'ced' txt3, 'su' txt4 FROM dual UNION ALL 10 SELECT 222 pid, 'test1' txt1, 'pak' txt2, 'ced2' txt3, 'su2' txt4 FROM dual UNION ALL 11 SELECT 333 pid, 'test2' txt1, 'pak3' txt2, 'ced3' txt3, 'su4' txt4 FROM dual UNION ALL 12 SELECT 444 pid, 'test2' txt1, 'pak3' txt2, 'ced4' txt3, 'su3' txt4 FROM dual) 13 SELECT b.pid, a.* 14 from table1 a 15 LEFT JOIN table2 b 16 ON (a.txt1 = b.txt1 OR 17 a.txt1 IS NULL AND a.txt2=b.txt2 OR 18 Nvl(a.txt2, a.txt1) IS NULL AND a.txt3 = b.txt3 OR 19 Nvl(a.txt2, a.txt1) IS NULL AND a.txt3 IS NULL AND a.txt4 = b.txt4); PID TXT1 TXT2 TXT3 TXT4 ---------- ------ ------ ------ ------ 111 test pak ced su 222 null pak ced2 su2 333 null null ced3 su3 444 null null null su3 null text5 null null su3 null null null null null
John
-
Query of queries: error when you try to fake Left Outer Join
Hello
I'm trying to reproduce a left outer join, combining two query of queries using a method I find here
However, I get an error message...
Here is the code I use...
< cfquery dbtype = "query" name = "qry" >
SELECT *.
OF returnQry, returnQry2
WHERE returnQry.mediumImage = returnQry2.mediumImage
ORDER BY returnQry.name
< / cfquery >
< name cfquery = "returnQry3", dbtype = "#application.mx #" >
SELECT *.
OF trackmeanings t
< / cfquery >< cfquery dbtype = "query" name = "endQry" >
SELECT name, nameRcd, mediumImage, comments COUNT (sMessage)
OF qry, returnQry3
WHERE qry.name = returnQry3.sNameTrack
UNION
SELECT name, nameRcd, mediumImage, comments COUNT (sMessage)
OF qry, returnQry3
WHERE #qry.name # NOT IN (#QuotedValueList (returnQry3.sNameTrack) #)
GROUP BY name, nameRcd, mediumImage
< / cfquery >When I try to use the query output in a page, I get the error message "incorrect conditional expression, waiting for an a [as |]» null | between | in | "comparison condition.
Anyone have any ideas?
Thank you very much
The items in the list should be cited. Since you are using quotedvaluelist, it's weird that they aren't. However, if you use cfqueryparam, list = Yes, you should have better luck. Among other things, it will protect you against the apostrophe in names.
-
Join inner &; outer join in a query
I have 11 paintings, 10 tables need will always be a match on the id, table 11 may or my not have a football game. I need to print information from the 10 tables with a matching id and the information in the table 11 if a record is found.
Help, please.
There is nothing wrong with having 10 inner joins and 1 outer join.
The syntax might look like this ANSII shaped:
Of
1Table INNER JOIN
2table ON (1Table.key = 2Table.KEY) JOIN IN-HOUSE
3Table ON (1Table.key = 3Table.KEY) JOIN IN-HOUSE
4Table ON (1TAble.key = 4Table.key) JOIN IN-HOUSE
INNER JOIN 5Tableau ON (1Table.key = 5table.key)
6Table ON (1Table.key = 6table.key) JOIN IN-HOUSE
INNER JOIN 7Table ON (1Table.key = 7Table.key)
8Table ON (1Table.key = 8Table.key) JOIN IN-HOUSE
INNER JOIN 9Table ON (1Table.key = 9Table.key)
10Table ON (1Table.key = 10Tablekey) LEFT OUTER JOIN
11Table ON (1Table.key = 11Table.key)
You can use paretheses more group the results if you wish.
When you create a relationship of this process the best resort is to do a table at the same time.
Build the query to return properly the expected effect of the first table. Then add the second and confirm that it is always the desired results. Continue to add the tables one at a time, stable all along the way.
Maybe you are looking for
-
All the text displays too large, Ctrl + 0 does not
Enabled Firefox this afternoon to find all the text made too big by about 30%. Icons in the bookmarks bar and the tabs are too big, as well. If I press on Ctrl + - twice, then it seems normal, but Ctrl + 0 returned any abnormally high. Gmail in parti
-
How long does it take for revised edition appears?
I downloaded my first iBook iAuthor to the iBooks on 7th store. It took a long time to download. I decided to do a revised edition. I created a short film instead of the trailer that was attached. I downloaded this as a revised version with success.
-
Unable to connect to wifi with new Apple TV 4th generation
I tried to connect to the wi - fi using the new connect with a device and it doesn't seem to work. Rpet could not turn on Apple TV, try again later. Then I try to configure it manually, I have put my password and says no network connection, your wire
-
Original title: RUNDLL error has anyone seen a RUNDLL error C:\WINDOWS\dfgwovap.dll the specific module could not be found. Since this jumped on my computer, I can run is more my outlook program. I opened for 1 second and then closes. I reinstalled
-
Internet connection suddenly disappeared after that Win 7 updated today
Suddenly my Windows 7 computer has no internet. Seems to coincide with a series of critical updates that were installed this morning. Also, I can't do a restore for some reason any. The network icon shows the connection to my router and indicates t