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
Tags: ColdFusion
Similar Questions
-
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>
-
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. -
Left Outer Join help...
Hello world
I'm still trying to learn the SQL, and I can not specifically with the left outer join. I normally join tables using equijoin, but I don't get the right data set returns, and designed with the help of a left or right outer join would solve the problem...
Here is my SQL that works properly with 1 left outer join. I build the slow query in the SQL following, you will see where I see the error. I don't expect you to understand the data and the columns, I'm trying to join, I think the problems I encounter are related to syntax, and I hope that you can find where are my syntax errors.
Select
s.Name as "Pseudonym,"
SV.view_name as "name of the view.
s_view. Name
Of
s s_screen,
s_screen_view sv
outer join left s_view
WE (sv.view_name = s_view.name)
where
SV.screen_id = ' 1-866 A - 1X3LU' and
s.ROW_ID = sv.screen_id and
s.repository_id = ' 866 A-1-1"and
s_view.repository_id = ' A-1-1 866 ";
Here is the SQL code where I encounter the following error...
Error:
ORA-00904: "SV". "" View_name ": invalid identifier
00904, 00000 - '% s: invalid identifier '.
* Cause:
* Action:
Error on line: column 14: 7
Problematic SQL:
Select
s.Name as "Pseudonym,"
SV.view_name as "name of the view.
s_view. Name,
s_applet. Name as Applet
-b.SID like "name of the cmdlet.
Of
s s_screen,
s_screen_view sv,
wti s_view_wtmpl_it
outer join left s_view
WE (sv.view_name = s_view.name)
outer join left s_applet
WE (wti.name = s_applet.name)
where
SV.screen_id = ' 1-866 A - 1X3LU' and
s.ROW_ID = sv.screen_id and
s.repository_id = ' 866 A-1-1"and
s_view.repository_id = ' A-1-1 866 ";
Thanks in advance for your help.
Chris
> ORA-00904: "S_VIEW_WEB_TMPL." "" ROW_ID ": invalid identifier
I don't see this table in your FROM clause.
-
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.
-
LEFT OUTER JOIN, trigger after QUERY problem
Hello
Guide to please the following
I wrote under query in QUERY after a BLOCK of TABULAR DATA, not as a single text element, called INVENTORY_ITEM
Select c.cat |' '|| s.SubCat |' '|| L1.lvl1 POINT IN: DATABLOCK. INVENTORY_ITEM
of itemcat c
LEFT OUTER JOIN itemsubcat s on (c.catid = s.catid)
LEFT OUTER JOIN lvl1 l1 on (s.subcatid = l1.subcatid)
When I compile the module an error is generated
«* ' Met the 'LEFT' symbol when waiting for one of the following values for the group with intersect less order start union where connect '.» *
Top query works fine with ORACLE SQL DEVELOPER.
Any solution please.
Kind regards -
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')
-
Left Outer Join does not work why?
Hello
I have a question I want to return all the id group grp_id table and count and give me a count of all "active" members in the Member table. There are a few members who are not active in the table of members who belong to groups in the grp_id table. I still want a record returned for these grpid, but since there is no active members for these groups, I would like a zero as the mbr_count. An active mbr is the one whose eff_dt is less than the date of the day and whose exp_dt is greater than today's date.
I have listed the query below, which returns active records mbr, but unfortunately does not return a grpid (as in my example of data) is not an active member (grpid: has ""). I have also provided the DDL for both tables as well as some examples of data that gives me the (Incorrect) results, that I posted. I have also posted what I need (the 'Correct' results).
Thanks for any help... (I use PL/SQL)
THE QUERY I USE:
=============
SELECT
G00.grpid,
Count (M00.grpid) mbr_count
Of
g00 grp_id
LEFT OUTER JOIN
m00 MBR on
G00.grpid = m00.grpid
WHERE
M00.eff_dt < sysdate
AND
M00.exp_dt > sysdate
GROUP BY
G00.grpid
It gives me results like:
INCORRECT RESULTS:
===============
GRPID MBR_COUNT
A 2
B 2
C 1
I want to see is:
CORRECT RESULTS
===============
GRPID MBR_COUNT
A 2
B 2
C 1
D 0
Here's the DOF and the sample data:
create table grp_id (grpid varchar (1))
insert into grp_id values ('A')
insert into grp_id values ('B')
insert into grp_id values ('C')
insert into grp_id values (')
Commit
create table mbr (mbr_name varchar (10), varchar (1) grpid, eff_dt date, exp_dt date)
insert into values of mbr ('BRAND', 'A', to_date (January 1, 2011 ',' DD-MM-YYYY '), to_date (July 1, 2011 ',' DD-MM-YYYY '))
insert into values of mbr ('BRAND', 'A', to_date (July 1, 2011 ',' DD-MM-YYYY '), to_date (1 January 2012 ',' DD-MM-YYYY '))
insert into values of mbr ('MARTY', 'A', to_date (January 1, 2011 ',' DD-MM-YYYY '), to_date (July 1, 2011 ',' DD-MM-YYYY '))
insert into values of mbr ('MARTY', 'A', to_date (July 1, 2011 ',' DD-MM-YYYY '), to_date (1 January 2012 ',' DD-MM-YYYY '))
insert into values of mbr ('FRANK', 'B', to_date (January 1, 2011 ',' DD-MM-YYYY '), to_date (July 1, 2011 ',' DD-MM-YYYY '))
insert into values of mbr ('FRANK', 'B', to_date (July 1, 2011 ',' DD-MM-YYYY '), to_date (1 January 2012 ',' DD-MM-YYYY '))
insert into values of mbr ('MARY', 'B', to_date (January 1, 2011 ',' DD-MM-YYYY '), to_date (July 1, 2011 ',' DD-MM-YYYY '))
insert into values of mbr ('MARY', 'B', to_date (July 1, 2011 ',' DD-MM-YYYY '), to_date (1 January 2012 ',' DD-MM-YYYY '))
insert into values of mbr ('JOHN', 'C', to_date (January 1, 2011 ',' DD-MM-YYYY '), to_date (July 1, 2011 ',' DD-MM-YYYY '))
insert into values of mbr ('JOHN', 'C', to_date (July 1, 2011 ',' DD-MM-YYYY '), to_date (1 January 2012 ',' DD-MM-YYYY '))
insert into values of mbr ("NOAM" 'd', to_date (January 1, 2011 ',' DD-MM-YYYY '), to_date (July 1, 2011 ',' DD-MM-YYYY ') ")Thanks for the script, shame on the missing semicolon :)
Your date restrictions are implemented as "filter predicates" rather than "join predicates.
that is the difference between a place ANDS extra o in the JOIN clause.SQL> SELECT 2 g00.grpid, 3 count(m00.grpid) mbr_count 4 FROM 5 grp_id g00 6 LEFT OUTER JOIN 7 mbr m00 on 8 g00.grpid = m00.grpid 9 WHERE 10 m00.eff_dt < sysdate 11 AND 12 m00.exp_dt > sysdate 13 GROUP BY 14 g00.grpid 15 / G MBR_COUNT - ---------- A 4 B 4 C 2 SQL> SELECT 2 g00.grpid, 3 count(m00.grpid) mbr_count 4 FROM 5 grp_id g00 6 LEFT OUTER JOIN 7 mbr m00 on 8 g00.grpid = m00.grpid 9 AND 10 m00.eff_dt < sysdate 11 AND 12 m00.exp_dt > sysdate 13 GROUP BY 14 g00.grpid; G MBR_COUNT - ---------- D 0 A 4 B 4 C 2 SQL>
-
Using Left Outer Join with reference
I have three tables.
Table 1: BOOK_DETAILS
Fields: BOOK_ID, BOOK_NAME
Table 2: BOOK_ISSUE_RECORD
Fields: BOOK_ID, USER_NAME
Table 3: BOOK_AUTHOR
Fields: BOOK_ID, AUTHOR_NAME
I must link table 1 and table 2 with a left outer join, because even if the book is not the questions to anyone, his name should come.
I have once again display the name of the author of books for each book.
I am able to create a query with the left outer join between table 1 and table 2. However, I am not able to give a reference to Table 3.
Can someone help me with this please.
Concerning
Hawkerselect d.book_name, a.book_author, i.user_name from book_details d join book_author a on (d.book_id = a.book_id) left join book_issue_recors i on (d.book_id = i.book_id) /
SY.
-
Hi all
I use under version
Connected to Oracle Database 11g Express Edition Release 11.2.0.2.0
SQL > SELECT E.ENAME,.
2 D.DEPTNO,
3 D.LOC
4. TO EMP E,.
DEPT 5 D
6. WHERE = E.DEPTNO D.DEPTNO (+);
ENAME, DEPTNO LOC
---------- ------ -------------
DALLAS SMITH 20
ALLEN 30 CHICAGO
WARD 30 CHICAGO
20 DALLAS JONES
MARTIN 30 CHICAGO
BLAKE 30 CHICAGO
CLARK 10 NEW YORK
SCOTT 20 DALLAS
THE 10 NEW YORK KING
TURNER 30 CHICAGO
20 DALLAS ADAMS
JAMES 30 CHICAGO
FORD 20 DALLAS
MILLER 10 NEW YORK
40 BOSTON
15 selected lines
-----------------------------------------------------------------------------------------------------------------------------
SQL > SELECT E.ENAME,.
2 D.DEPTNO,
3 D.LOC
4. TO EMP E
5 LEFT OUTER JOIN
D 6 DEPT
7. THE E.DEPTNO = D.DEPTNO;
ENAME, DEPTNO LOC
---------- ------ -------------
MILLER 10 NEW YORK
THE 10 NEW YORK KING
CLARK 10 NEW YORK
FORD 20 DALLAS
20 DALLAS ADAMS
SCOTT 20 DALLAS
20 DALLAS JONES
DALLAS SMITH 20
JAMES 30 CHICAGO
TURNER 30 CHICAGO
BLAKE 30 CHICAGO
MARTIN 30 CHICAGO
WARD 30 CHICAGO
ALLEN 30 CHICAGO
14 selected lines
My doubt is both are same query is the same, is in ansi format and is in the format of the Oracle,.
but the results are different.
For the first query null is coming for unmatched records in the dept table
but in the second query, it does not come
Thank you
Hello
2947022 wrote:
Hi all
I use under version
Connected to Oracle Database 11g Express Edition Release 11.2.0.2.0
SQL > SELECT E.ENAME,.
2 D.DEPTNO,
3 D.LOC
4. TO EMP E,.
DEPT 5 D
6. WHERE = E.DEPTNO D.DEPTNO (+);
ENAME, DEPTNO LOC
---------- ------ -------------
DALLAS SMITH 20
ALLEN 30 CHICAGO
WARD 30 CHICAGO
20 DALLAS JONES
MARTIN 30 CHICAGO
BLAKE 30 CHICAGO
CLARK 10 NEW YORK
SCOTT 20 DALLAS
THE 10 NEW YORK KING
TURNER 30 CHICAGO
20 DALLAS ADAMS
JAMES 30 CHICAGO
FORD 20 DALLAS
MILLER 10 NEW YORK
40 BOSTON
15 selected lines
-----------------------------------------------------------------------------------------------------------------------------
SQL > SELECT E.ENAME,.
2 D.DEPTNO,
3 D.LOC
4. TO EMP E
5 LEFT OUTER JOIN
D 6 DEPT
7. THE E.DEPTNO = D.DEPTNO;
ENAME, DEPTNO LOC
---------- ------ -------------
MILLER 10 NEW YORK
THE 10 NEW YORK KING
CLARK 10 NEW YORK
FORD 20 DALLAS
20 DALLAS ADAMS
SCOTT 20 DALLAS
20 DALLAS JONES
DALLAS SMITH 20
JAMES 30 CHICAGO
TURNER 30 CHICAGO
BLAKE 30 CHICAGO
MARTIN 30 CHICAGO
WARD 30 CHICAGO
ALLEN 30 CHICAGO
14 selected lines
My doubt is both are same query is the same, is in ansi format and is in the format of the Oracle,.
but the results are different.
For the first query null is coming for unmatched records in the dept table
but in the second query, it does not come
Thank you
In fact, these requests are not the same.
The first is to find all the lines of the Department, with the corresponding lines of PGE (when there are). This is equivalent to «FROM dept LEFT OUTER JOIN emp...» ».
The second is to find all the rows in the emp of the lines of the Department (when there are any). This is equivalent to «...» WHERE e.deptno = d.deptno (+).
-
Bad result in a left outer join in 12.1.0.2
Hallo,
We discovered a strange behaviour in a query. The query provides values in a column of outer join where there is no corresponding value in the table is attached to the outside.
When you expand this request by the "ORDER BY" then this query gives the correct result.
Example:
SQL > desc tb_a
Name Null? Typ
-------------------------------------------- ----------------------------
ID NOT NULL NUMBER (19)SQL > desc tb_b
Name Null? Typ
-------------------------------------------- ----------------------------
CLOSED NOT NULL NUMBER (1)
ID NOT NULL NUMBER (19)CCS_APPLICATION@icw01> select * from tb_a where id in (4148,4141,4195);
ID
----------
4148
4141
4195CCS_APPLICATION@icw01> select * from tb_b where id in (4148,4141,4195);
INTERNAL ID
---------- ----------
4148 0CCS_APPLICATION@icw01> SELECT
2 b.id AS b_id,
3 a.id AS a_id,
4 b.closed AS b_closed
5
6 tb_a a
7 LEFT OUTER JOIN tb_b b ON a.id = b.id
8 WHERE a.id IN (4148, 4195, 4141)
9 ORDER BY ASC a.id
10;B_ID ALLOCATION A_ID B_CLOSED
---------- ---------- ----------
4141
4148 4148 0
4195CCS_APPLICATION@icw01> SELECT
2 b.id AS b_id,
3 a.id AS a_id,
4 b.closed AS b_closed
5
6 tb_a a
7 LEFT OUTER JOIN tb_b b ON a.id = b.id
8 WHERE a.id IN (4148, 4195, 4141)
9 - ORDER BY ASC a.id
10;B_ID ALLOCATION A_ID B_CLOSED
---------- ---------- ----------
4148 4148 0
4141 4141
4195 4195instance parameter:
VALUE OF TYPE NAME
------------------------------------ ----------- ------------------------------
compatible string 12.1.0.2.0
optimizer_features_enable string 12.1.0.2
After ""alter system set optimizer_features_enable = ' 11.2.0.4 ';" the query provides the correct result in both cases (ordered and unordered).
Now the final question: is this a bug?
1480970 wrote:
Hallo! Yes, I searched the Support of Oracle. I found some similar entries, but not an exact match. To fix some issues
with 12.1.0.2.
There is another interesting clue when look you on the execution plan:
Note
-----
-the dynamic statistics used: dynamic sampling (level = 2)
- This is an adaptation plan
We have disabled (= FALSE) optimizer_adaptive_features and the query provides the correct values.
This could be a solution for us.
Looks like a pretty tight match for bug 18430870, even if it affects the two 12.1.0.1 and 12.1.0.2, which contradicts the Martin trial against 12.1.0.1.
The description of the bug mentions disabling "_projection_pushdown" (set to false) should also be a viable solution, perhaps if you want to give that a try and see if it is a different bug or not.
There are also a number of one-time fixes already available for download, maybe your version / platform is already covered, if the bug applies.
Randolf
-
Hi Experts,
I have a requirement that says - see the chart for the past 10 days, regardless the presence data table in fact.
Lets consider an example - Time_dim product, are my dimension tables, Purchase_Order is my fact table.I did it for external Purchase_Order in left RPD with TIME_DIM and inner join with the PRODUCT table. and execution of query of exit-
Select T.Date, P.item, count (distinct PO.order_no)
TIME_DIM t, PRODUCT P, PURCHASE_ORDER PO
where T.date_key = PO.date_key
and P.item = in. agenda
and P.item = 'laptop ';The query generated by OBIEE left outer join, but when the condition P.item = "Notebook" included in the query, and if there are no orders for this product in one of the date, that date will not come in the result set.
the query to be generated by the OBIEE is-
Select T.Date, PO.item, count (distinct PO.order_no)
TIME_DIM t,.
(SELECT P.ITEM, IN. ORDER_NO
PRODUCT P, PO PURCHASE_ORDER
WHERE P.item = in. agenda
and P.item = 'Laptop') IN.
WHERE T.date_key = PO.date_key (+);How to design the RPD to achieve this. All pray to advise on this. Thanks in advance.
Thank you
ChantalHello
You are on 11.1.1.7?
I would say that your condition can be made without using external and maintenance of product and the standard between the FACT dimension, time inner join join.
If you enable your property analysis OBIEE "Include Null values" will automatically return all the elements of time and product matching your filter (so you'll need to add a filter on 'Date' to limit it to the last 10 days or you will have a unique day of your time dimension).
If you filter then on "Laptop", even if there is not a single value in order for "Laptop" in the last 10 days, he will be there on the screen.
Easy, clean and you keep your inner join between the facts and Dimensions.
Take a look at this example, I just did on SampleApp 406:
Selection of 12 months (year 2010) and a customer (id = 89) and income. The model has only an inner join. I activate the option "Include Null values" and here is the result.
A line with cells only empty because there is not a single revenue for customer 89 in 2010. This is exactly your condition.
Honestly, do not touch your model using the outer join, you will have more side effects than benefits. Every single scan will do the outer join and you'll have a lot of data 'empty' return of the DB (more large data set containing just the null values) and probably you need the outer join in 15 to 25% of your analysis.
Keep things simple, it will be faster and easier to maintain.
-
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.
-
Why left outer join with a table gives me more lines?
Hi gurus,
I can see "view_a" and a table 'table_a '.
view_a a county of 100 lines. Now, when I left outer join that discovers with a 'table_a', I expect all 100 lines.
However, I'm more than 100 lines. Is it still possible?
Also even to analyze these situations, how can I move forward?
Because it is very high volumn of sight and takes longer to run.
Select count (*) view_a, view_b
where view_a.col1 = view_b.col1 (+)
and view_a.col2 = view_b.col2 (+);
Thank you
I can see "view_a" and a table 'table_a '.
view_a a county of 100 lines. Now, when I left outer join that discovers with a 'table_a', I expect all 100 lines.
However, I'm more than 100 lines. Is it still possible?
Also even to analyze these situations, how can I move forward?
Because it is very high volumn of sight and takes longer to run.
Select count (*) view_a, view_b
where view_a.col1 = view_b.col1 (+)
and view_a.col2 = view_b.col2 (+);
Which is not necessarily related to the use of an outer join.
Just join of two tables in general will give you more rows of one table has.
Scott DEPT table contains ONE row for deptno = 10
The EMP table has THREE rows of deptno = 10
The number of rows you plan if you join two tables using an equi-join?
Three - what is MORE lines the DEPT table has for deptno = 10
Select * from Department where deptno = 10
DEPTNO, DNAME, LOC
10, ACCOUNTING, NEW YORKSelect * from emp where deptno = 10
MGR, EMPLOYMENT ENAME, EMPNO, HIREDATE, SAL, COMM, DEPTNO
7782, CLARK, MANAGER, 7839, 6/9/1981,2450, 10
7839, KING, PRESIDENT, 17 NOVEMBER 00, 10
7934, MILLER, CLERK, 7782, 23 JANUARY 00: 10Select dept.*, emp.*
Department, emp
where dept.deptno = 10
and dept.deptno = emp.deptnoDEPTNO, DNAME, LOC, EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO_1
10, ACCOUNTING, NEW YORK, 7782, CLARK, MANAGER, 7839, 6/9/1981,2450, 10
10, ACCOUNTING, NEW YORK, 7839, KING, PRESIDENT, 17 NOVEMBER 00, 10
10, ACCOUNTING, NEW YORK, 7934, MILLER, CLERK, 7782, 23 JANUARY 00: 10So if these are the lines ONLY in the table EMP and DEPT the query would give you THREE lines despite the DEPT table only ONE line.
No do you expect? You get ALL the child rows that belong to the parent company. Otherwise, how could it possibly work?
The OUTER join includes lines where the parent row exists but there is NO child line as others have shown.
Outer joins
Outer join extends the result of a simple join. Outer join returns all rows that satisfy the join condition and also returns some or all rows in a table for which no line of the other meet the join condition.
Get more lines to exist in one of the paintings is a basic necessity. It usually has NOTHING to with the question of whether you have an outside to join or not.
See the section on the JOINTS in the Oracle documentation
http://docs.Oracle.com/CD/B28359_01/server.111/b28286/queries006.htm
-
left outer join, after summarizing
Hello
I need to create a summary of a lot of tables and join the result set with another table. The other table must do a left outer join. When I do a left outer join, the column which do not appear in the second table appear as a draft. However, I would like to than all results in the table on the right to replicate once for each row in the left table. Here is a sample data set:
CREATE THE TRIGHT TABLE
(
PKEY CHAR(1),
AMT NUMERIC (13.2).
GRP TANK (4),
FILTER TANK (3)
)
INSERT INTO TRIGHT VALUES ('A', 200 ' GRP1 "," XXX ");
INSERT INTO TRIGHT VALUES ('A', 500, "GRP2', 'XXX'");
INSERT INTO TRIGHT VALUES ('A', 150 'GRP1', 'YYY');
INSERT INTO TRIGHT VALUES ('A', 100, "GRP2', 'YYY'");
CREATE THE TLEFT TABLE
(
PKEY CHAR (1)
)
INSERT INTO VALUES TLEFT ('A')
INSERT INTO TLEFT VALUES ('B')
SELECT A.PKEY, GRP, SUM (AMT) OF TLEFT A LEFT JOIN
(SELECT PKEY, GRP, SUM (AMT) AS AMT IN TRIGHT)
WHERE FILTER = "XXX".
PKEY, GRP) B
ON A.PKEY = B.PKEY
A.PKEY GROUP, GRP
The result I get is:
A 200 GRP1
A 500 GRP2
B (white) (white)
Instead, I would like the following:
A 200 GRP1
A 500 GRP2
GRP1 B 0
B GRP2 0
Can anyone help? Thanks in advance.
Sorry, I couldn't find the button skip yet, although there is an urgent need for such a feature in this forum.
That is why another chance for you:
SELECT
a.PKEY
GRP
SUM (case
When a.pkey = b.pkey
can AMT 0 otherwise
AMT end)
Of
TLEFT HAS
Cross JOIN
TRIGHT B
where FILTER = "XXX".
GROUP BY a.PKEY, GRP
ORDER BY a.PKEY, GRP
PKEY GRP AMT A GRP1 200 A GRP2 500 B GRP1 0 B GRP2 0
Maybe you are looking for
-
Notepad continues installation shortcuts in my office that says "destop.ini." When I opened the they say 'system configuration-block-notes' and have this note or something like this: root system blah blah blah: I always delete it and empty the trash.
-
Hello, I just the screen of death terrible 'white', I think... the Apple logo appears briefly (as well as a rasterized on top band: see the image), then everything goes black for a few seconds, then white... I tried the option key to HD or HD recover
-
How to install volume control program and retrieve the sound icon in the start bar
How to install volume control program and retrieve the sound icon in the start bar
-
can I add a sata dvd drive to foxconn mcp73m01h1
Compaq sr5450f products kj383aa #aba, {Personal Information deleted} - map mother foxconn mcp73m01h1 receiver has the sata connections 4 four. I guess I can use one for an additional hard drive - but I also use one for a dvd rw sata drive? The origi