outer join on the left, needs improvement
Two table t1 and t2 where t1.col1 = t2.col2create table t1 ( col1 varchar2(20));
insert into t1 values('aa');
insert into t1 values('bb');
insert into t1 values('cc');
insert into t1 values('dd');
insert into t1 values('ee');
create table t2 ( col2 varchar2(20) , col3 varchar2(20));
insert into t2 values('aa','q_aa');
insert into t2 values('bb',' ');
insert into t2 values('cc','q_cc');
insert into t2 values('dd',' ');
here is my join query:-
select t1.col1,t2.col2,t2.col3,
case when t2.col3 is not null then t2.col3
when t2.col3 is null then t1.col1 end as name1
from t1 left outer join t2
on t1.col1 =t2.col2
real to come resultCOL1 ^ ^ COL2 ^ ^ COL3 ^ ^ NAME1
AA ^ ^ ^ aa ^ ^ ^ q_aa ^ ^ ^ q_aa
BB ^ ^ ^ bb
CC ^ ^ ^ cc ^ ^ ^ q_cc ^ ^ ^ q_cc
JJ ^ ^ ^ JJ
ee^^^^^^^^^^^^^^^^ee
requirement of result
COL1 ^ ^ COL2 ^ ^ COL3 ^ ^ ^ NAME1
AA ^ ^ ^ aa ^ ^ ^ q_aa ^ ^ ^ q_aa
BB ^ ^ ^ bb ^ ^ ^ bb
CC ^ ^ ^ cc ^ ^ ^ q_cc ^ ^ ^ q_cc
JJ ^ ^ ^ DD ^ ^ ^ JJ
ee^^^^^^^^^^^^^^^^^ ee
and how can copy paste the result of sql * more... box when I copy paste here it automatically omit the space, as above
The problem is values col3 to the 'bb' and 'dd' lines are not null, because they have a space in them. You can either remove the space and use:
nvl(t2.col3,t1.col1) as name1
or tim space out:
nvl(trim(t2.col3),t1.col1) as name1
Tags: Database
Similar Questions
-
Outer joins to the left... Please help!
Hmm. Ive had trouble with this one for a while and have read and re-read docs etc.
IM under 11.2 XE and its Apex 4.2 application...
Its a simple query with outer joins... but I can't simply to do it right after several hours of trying! ID be very grateful if anyone can lend a hand...
For the query below. I am looking for the following:
Complete list of entities, a sum of the values if they exist (and obviously empty if they don't), filtered by a table of SUM choice only the records that match a value in the lookup table.
Select
e.ENTITY as ENTITY,
Sum (p.amount) as Forecast_Income,
Sum (BR.bri_credit) as Actual_Income,
Sum (BR.bri_debit) as Actual_Expenses
Of
e entities
LEFT OUTER JOIN payments p
WE (e.entity_id = p.entity_id)
LEFT OUTER JOIN pmt_stat_lookup ps
WE (p.status_id = ps.status_id
and ps.forecast = 'Y')
LEFT OUTER JOIN bri_recon br
WE (e.entity_id = br.entity_id)
E.entity group
My problem with the join where I join p.status_id for ps.status_id and ps.forecast = 'Y '... If I run the above statement, it seems does not account for this filter criteria and summarizes all records of PAYMENTS, regardless of... If I move outside the outer join clause, it only brings back the records of PAYMENTS where there is a join. Ive tried to join in a different order etc... but in vain...
If someone could help, Id be very grateful.
Kind regards
Richard
Hello Richard
Try this query:
SELECT e.entity as ENTITY
sum (PO.amount) as Forecast_Income
sum (br.bri_credit) as Actual_Income
sum (br.bri_debit) as Actual_Expenses
Of
E ENTITIES
LEFT OUTER
JOIN (SELECT P.entity_id )
P.amount
PAYMENTS P
JOIN PMT_STAT_LOOKUP PS
ON p.status_id = ps.status_id
AND ps.forecast = 'Y '.
) IN.
WE e.entity_id = in. entity_id
LEFT OUTER
JOIN BR BRI_RECON
ON e.entity_id = br.entity_id
E.entity GROUP
;
I hope it helps.
Best regards, David
Post edited by: David Berger
-
SSRS for lack of outer join with the Oracle data source
It seems to be a problem with the Oracle driver used in the Reporting SERVICES query designer.
When you use an Oracle data source, if I create an outer join in the graphic designer, it automatically inserts '{OJ' before the join and '} ' after her. This is an incorrect syntax for Oracle and refuses to start. The curly braces and the JO editable in designer text, but if I go back to the graphic designer and immediately to reintegrate them.
Only, this has started to happen a year or two ago - before that it worked, but with the old (+) syntax.
Can it not be healed? It makes things very difficult.
-Geoff
Hi Geoff,
Thanks for posting in the Microsoft Community.
However, the question you posted would be better suited in the Forums of the Oracle Support; We recommend that you post your query in Oracle Support Forums to get help:
If you have any other questions or you need Windows guru, do not hesitate to post your questions and we will be happy to help you.
-
using outer joins if the two column is null? Use only (+)
Hi all
create the table xxc_tr_num (tl_number number, tr_no number tl_no_id);
insert into xxc_tr_num values (123,100,222);
insert into xxc_tr_num values (124,100,333);
create the table xxc_od_tab (tl_number number, tl_id number);
insert into xxc_od_tab values (123,001);
insert into xxc_od_tab values (null, null);
create table xxc_oth_tab (name varchar2 (10), number of tl_id);
insert into xxc_oth_tab values('abc',,001);
insert into xxc_oth_tab values (null, null);
Wait it out put
tr_no tl_no_id name
100 222 abc
100 333
using outer joins if the two column is null? use only please of outer joins
And I tried to use outer joins on both tl_id column but not get values and I use have County (tr_no ) > 1
Rajesh123 wrote:
Thank you Kiss it is not possible to use having clause?
You need to understand the functioning of the group. If you will not be asked this question.
Check this box
SQL> select tr_no, 2 tl_no_id, 3 count(*) 4 from xxc_tr_num a, 5 xxc_od_tab b, 6 xxc_oth_tab c 7 where a.tl_number = b.tl_number(+) 8 and b.tl_id = c.tl_id(+) 9 group 10 by tr_no 11 , tl_no_id; TR_NO TL_NO_ID COUNT(*) ---------- ---------- ---------- 100 333 1 100 222 1
See what returns the count? You have grouped according to TR_NO and TL_NO_ID. You must take into consideration the TL_NO_ID just put COUNT (TR_NO) does not increase the NUMBER of the whole group. To get the NUMBER on the whole group, I used the analytical function and did. Like this, see the number of the analytical function here
SQL> select tr_no, 2 tl_no_id, 3 count(*), 4 count(*) over(partition by tr_no) 5 from xxc_tr_num a, 6 xxc_od_tab b, 7 xxc_oth_tab c 8 where a.tl_number = b.tl_number(+) 9 and b.tl_id = c.tl_id(+) 10 group 11 by tr_no 12 , tl_no_id; TR_NO TL_NO_ID COUNT(*) COUNT(*)OVER(PARTITIONBYTR_NO) ---------- ---------- ---------- ------------------------------ 100 222 1 2 100 333 1 2
So to answer your question, yes you can't do in the HAVING clause...
-
Outer join on the Filter Condition
Hello
I would like to show all rows in a query for two conditions to filter on the 'status '. I used an outer join on the outer query to return the values inside the inline query, but it returns not to return all rows.
create table (test)
ID number,
start_date date,
status varchar2 (1).
number of amount,
number of cust_type
);
Insert test values (001, June 1, 2014 ", am ', 189, 78");
Insert test values (001, March 26, 2014 ", 'R', 175, 4");
Insert test values (001, December 1, 2014 ", 'R', 89, 91");
Insert test values ("001, 13 August 2014 ', 'J', 19, 2);
Insert test values (001, 12 August 2014 ', 'E', 19, 2);Insert test values (002, January 1, 2014 ', 'R', 17, 4);
Insert test values (002, 26 June 2014 ", 'R', 175, 4");
Insert test values (' 002, February 1, 2014 ', 'J', 9, 8);
Insert test values (002, 13 October 2014 ', ', 190, 2);Insert test values (' 003, June 1, 2014 ', 'J', 189, 78);
Insert test values (003, March 26, 2014 ", 'R', 175, 4");
Insert test values (003, December 1, 2014 ", 'R', 89, 91");
Insert test values (' 003, 13 August 2014 ', 'J', 19, 2);
Insert test values (' 003, 12 August 2014 ', 'J', 19, 2);commit;
Select i.ids, i.start_date, i.cust_type, i.amount as gross_amount, i.amount + ii.amount as net_amount
test I have,
(select id, amount)
of the test
where (status = status or 'R' = 'J')) ii
where i.cust_type in (4, 78, 91, 2, 4, 8)
and i.ids (+) = ii.ids
and i.status (+) to (', 'E')
"and i.start_date between 1 January 14 ' and 31-dec-2014."The query above exclude ID 003 because there is that no status (M / E) butI want always display all codes, even if the condition is not consistent
Hello
Want results from an inner join to match identifiers, but the results of an outer join for identifiers that are not? In other words, you want to include the rows of the table I only when one of the following is true:
The line of table I have ticked all the boxes, or
No line in not table i with the same ID meets all conditions
?
If so, here's a way to do it:
WITH got_rnk AS
(
Select i.ids, i.start_date, i.cust_type
, nvl2 (ii.ids, i.amount, 0) as gross_amount
, i.amount + nvl (ii.amount, 0) as net_amount
dense_rank () over (partition of i.ids
order of nvl2 (ii.ids, 'A', 'B')
) as rnk
I have test
(in left outer join
SELECT ID, amount
of the test
where status ('R', 'J')
) ii on i.ids = ii.ids
and i.cust_type in (4, 78, 91, 2, 4, 8)
and i.start_date between to_date (January 1, 2014 ", 'dd-mon-yyyy')
and to_date (31-dec-2014', 'dd-mon-yyyy')
and i.status in (', 'E')
)
SELECT ID, start_date, cust_type
gross_amount, net_amount
of got_rnk
where rnk = 1
;
Results of your sample data:
ID START_DATE GROSS_AMOUNT NET_AMOUNT CUST_TYPE
--------- ----------- ---------- ------------ ----------
1 1 June 2014 78 189 364
1 1 June 2014 78 189 278
1 1 June 2014 78 189 208
1 12 August 2014 2 19 38
1 12 August 2014 2 19 108
1 12 August 2014 2 19 194
2 13 October 2014 2 190 207
2 13 October 2014 2 190 365
2 13 October 2014 2 190 199
3 March 26, 2014 4 0 175
3 1 June 2014 78 0 189
3 12 August 2014 2 0 19
3 August 13, 2014 2 0 19
3 1 December 2014 91 0 89
-
outer join in the view criteria
Hello world
I use jdeveloper 11.1.1.6.0
I want to create outer join in the view criteria, so I had to substitute getCriteriaItemClause ViewObjImpl.java method
my query is like this:
SELECT t1. row_no, t2.type FROM table_1 t1, t2 from table_2
WHERE t1. row_no (+) = t2. row_no
and t1.user_Id (+) =: bindVar
table_1 (row_no, user_Id)
table_2 (row_no, type)
the part " t1.user_Id (+) =: bindVar " should be put in the display criteria
the method:
@Override
public String getCriteriaItemClause (ViewCriteriaItem viewCriteriaItem) {}
String newQeury = this.getEntityDef (0) .getAliasName () + "." + viewCriteriaItem.getColumnName () + "(+) =:bindVar .
Return newQeury;
}
but when I run the criteria see exception below raises:
oracle.jbo.expr.JISyntaxError: Houston-36000: an unexpected token expression is found.
When I remove the sign "(+)" of newQeury
String newQeury = this.getEntityDef (0) .getAliasName () + "." + viewCriteriaItem.getColumnName () + "=:bindVar . remove the sign "(+)" before =:bindVar
raises the exception below
Houston-29000: Unexpected exception caught: oracle.jbo.expr.JIEvalException, msg = Houston-25077: t1 name not found in the given object: ViewRow [[5-1-5] oracle.jbo.Key].
Habib
This is a duplicate of https://forums.oracle.com/thread/2577092
Please do not post your questions several times.
A possible solution posted to the original thread.
Timo
-
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')
-
outer join with the additional constraint
Hello
With the help of Oracle 11 g R2.
I would of outer join tables 2 together and put down restrictions on the types of records that are returned in the query result. Here's a mock-up of the tables and data.
create table aaa (col1 number not null, col2 number not null)
create table bbb (col1 number not null, col2 number not null)
insert into values of aaa (1: 80)
insert into values aaa (2, 90)
insert into values aaa (3, 80)
insert into values aaa (4, 90)
insert into values aaa (5, 80)
insert into bbb values (3, 600)insert into values of bbb (4, 700)
This is the query
select a.col1, a.col2, b.col1, b.col2 from aaa a, bbb b where a.col1 = b.col1 (+) and (a.col2, b.col2) <> ((90, 700))
The result of the query is as follows.
col1 col1 col2 col2
1 80
3 80 3 600
5 80
Where col1 = 4 has been deleted, which is an expected result. However, where col1 = 2 has also been removed, which is not a desired outcome. Your response is appreciated.
Hello
Here is a way that works for the given sample data:
SELECT *.
AAA a
LEFT OUTER JOIN bbb b ON a.col1 = b.col1
WHERE the NVL (a.col2, 0) <> 90
OR NVL (b.col2, 0) <> 700
;
I don't know if that will satisfy your requirements with other data, since you didn't say what your needs are.
Whenever you have a WHERE clause is applied after the outer join, all columns of the table in option (table bbb in this example) must be used in an NVL, NVL2 or something like a CASE expression that takes into account null values; otherwise, the effect will be the same as an inner join.
-
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 to specify an outer join in the query designer
I quickly built a large query with the query designer, and it works very well, but does not produce 9 disks on 2200 - so I need to change to an outer join.
My problem is that I can't find a way to specify an outer join. I tried to change the query, query builder formed, but it won't let me.
I know that I can capture the query, edit and run it in sql developer and that works fine, but I want to use the Query Builder as it is the fastest way I know to quickly add and remove items - my users don't know exactly what that it to include.
I know it's kind of a trivial question, but I searched the forum, manual, the web and no luck
Thanks for any help you can give
GlennHi Glenn,.
When you use the query designer to create the sql statement, you must click on the empty box to the right of the fields in each table to create the join. When you are finished, you should see a line drawn between the two tables. Click on this line, and a small window appears allowing you to select inner outer or right outer joins, left.
When the report was created, however, you must change the statement. For example, if you use the query designer to join DEPT at EMP based on the DEPTNO field on the two tables, you get:
select "DEPT"."DEPTNO" as "DEPTNO", "DEPT"."DNAME" as "DNAME", "DEPT"."LOC" as "LOC", "EMP"."EMPNO" as "EMPNO", "EMP"."ENAME" as "ENAME", "EMP"."JOB" as "JOB", "EMP"."MGR" as "MGR", "EMP"."HIREDATE" as "HIREDATE" from "EMP" "EMP", "DEPT" "DEPT" where "DEPT"."DEPTNO"="EMP"."DEPTNO"
This is to change:
select "DEPT"."DEPTNO" as "DEPTNO", "DEPT"."DNAME" as "DNAME", "DEPT"."LOC" as "LOC", "EMP"."EMPNO" as "EMPNO", "EMP"."ENAME" as "ENAME", "EMP"."JOB" as "JOB", "EMP"."MGR" as "MGR", "EMP"."HIREDATE" as "HIREDATE" from "EMP" "EMP" LEFT OUTER JOIN "DEPT" "DEPT" ON "DEPT"."DEPTNO"="EMP"."DEPTNO"
Andy
-
How to improve the performance of the left external joiin
Hello:
I have a problem on the left outer join.
Here is the example:
SELECT A.N, GISELE
A.
LEFT OUTER JOIN B ON A.N = B.N
The main problem is that if the lines of A is 1000, and B is 10,000,000, this sql speed
still weak, is - is it possible to improve this. Thank you very much.Hello
rp0428 wrote:
Of course - this will do:SELECT N FROM A;
Hah - you got this question in an interview?
If you did it was a trick question.
It's more complicated than you think.
What you gave would be the exact equivalentSELECT A.N -- , B.N FROM A LEFT OUTER JOIN B ON A.N=B.N
However, for the second column in the output, we really need to look at table B.
I suspect that the outer join is the fastest way to get results. Make sure that n is indexed, and that statistics are up-to-date.
If you want to try another way, here is one:SELECT n , ( SELECT n FROM b WHERE n = a.n AND ROWNUM = 1 ) AS b_n FROM a ;
Published by: Frank Kulash, March 21, 2013 21:29
Added example scalar subquery. -
Outer join to find the missing?
I have 2 tables:
with stud_courses as
(
Select studentid 111, 2, 2201 coursecategory courseid, 'A' GRADE of double
Union
Select studentid 111, 2, 2203 coursecategory courseid, CATEGORY "B" of the double
Union
Select studentid 111, 4 coursecategory, 2121 courseid, 'A' GRADE of double
Union
Select studentid 222, 3 coursecategory, 1111 courseid, 'A' GRADE of double
Union
Select studentid 222, 3 coursecategory, 1112 courseid, 'A' GRADE of double
)
course_categories as
(
Select 2 coursecategory, 2201 courseid double
Union
Select 2 coursecategory, 2202 courseid double
Union
Select 2 coursecategory, 2203 courseid double
Union
Select 2 coursecategory, 2204 courseid double
Union
Select 3, 1110 coursecategory courseid double
Union
Select 3 coursecategory, 1111 courseid double
Union
Select 3 coursecategory, 1112 courseid double
Union
Select 3 coursecategory, 1113 courseid double
Union
Select 4 coursecategory, 2120 courseid double
Union
Select 4 coursecategory, 2121 courseid double
Union
Select 4 coursecategory, 2122 courseid double
Union
Select 4 coursecategory, 2123 courseid double
)
For each student, wants to add the missing courseids for the coursecategory he takes. So student because 111 is in coursecategory 2 I should be able to show all results for him, including the ID of course 2202 and 2204 of category 2 and 2120, 2122, 2123 for this child
My end result would be something like:
StudentID, courseid, coursecategory, grade
111,2,2201, "A".
111,2,2201, '
111,2,2203, 'B '.
111,2,2201, '
111,4,2120, '
111,4,2121, "A".
111,4,2122, '
111,4,2123, '
222,3,1110, '
222,3,1111, "A".
222,3,1112, "A".
222,3,1113, '
I know how to do it with a Union and not exists, but I was wondering if I could do it with an outer join.
I would appreciate your help.
Thank youHello
Yes, you can do it with an outer join. The tricky thing is you need outside to join the table real stud_courses to something that has valid all combinations of the studnents and prices. There is no single table that contains it; the following query will receive these combinations by making a cross join:
WITH all_students AS ( SELECT DISTINCT studentid FROM stud_courses ) , got_category_cnt AS ( SELECT all_s.studentid , c.coursecategory , c.courseid , NVL ( s.grade , 'M' ) AS grade , COUNT (s.grade) OVER ( PARTITION BY all_s.studentid , c.coursecategory ) AS category_cnt FROM all_students all_s CROSS JOIN course_categories c LEFT OUTER JOIN stud_courses s ON s.studentid = all_s.studentid AND s.courseid = c.courseid ) SELECT studentid , coursecategory , courseid , grade FROM got_category_cnt WHERE category_cnt > 0 ORDER BY studentid , coursecategory , courseid , grade ;
The results I get are:
`STUDENTID COURSECATEGORY COURSEID G ---------- -------------- ---------- - 111 2 2201 A 111 2 2202 M 111 2 2203 B 111 2 2204 M 111 4 2120 M 111 4 2121 A 111 4 2122 M 111 4 2123 M 222 3 1110 M 222 3 1111 A 222 3 1112 A 222 3 1113 M
These are a little different from what you have posted.
user9207291 wrote:
...
StudentID, courseid, coursecategory, grade
111,2,2201, "A".
111,2,2201, '
111,2,2203, 'B '.
111,2,2201, '
111,4,2120, '
111,4,2121, "A".
111,4,2122, '
111,4,2123, '
222,3,1110, '
222,3,1111, "A".
222,3,1112, "A".
222,3,1113, 'Is it because there are errors in what you posted? Do you really want to have three lines of output for the same studentid (111) and courseid (2201)?
Looks like there should be a slick way to do this with a partitioned outer join.
A partitioned outer join matches each row of table A with the lines in table B, but, if there is no correspondence between a given A line and a line to a given partition of B, that the rank of A and the B partition is included in the game anyway. Here, we want the two partition tables. -
Show all dates between date range (time Dimension is left outer join)
All,
I did some research on this issue, but in all positions on date variables, date prompts and date filtering I have not seen one exactly to my question (perhaps that they are and I don't have my head around it properly yet).
My requirement of report is to allow a user to select a start date and an end of day. The report is expected to show the activity of these two days - AND display 0/null on days where there is no activity. This second part is where I am getting hung up.
The paintings in question are:
Timedim
EventFact
CustomerDim
My MDB is configured as follows:
Left outer join of Timedim EventFact
Inner join CustomerDim EventFact
If I run a report by selecting the DAYS of Timedim and an EventFact measure1 with range day 01/01/2010-31/12/2010... A record for each day and it looks perfect because of the left outer join between Timedim and CustomerDim.
But... If I add a CustomerDim field, Select TimeDim.DAY, CustomerDim.CUSTNAME, EventFact.MEASURE1, OBIEE returns only records for the days that have record EventFact.
This is due to the fact that the Timedim is always external joined in EventFact, but adding in fact CustomerDim OBIEE set up an inner join between tables that will only return data where there are data EventFact.
There is a way around it in this simple case, and that is to define the relationship between CustomerDim and EventFact as an outer join as well. This will give the desired effect (but an outer join between the two tables is not the real relationship) and I have add an extra dimension and add additional sources of logic to a single dimension in MDB it becomes complicated and messy.
Also, ive ruined with the definition of the conduct in the relationship table, etc... but he gave not the desired effect.
Has anyone ever met the need for force display all dates within a range specified with a fact table that does not have an entry for each date?
Thanks in advance.
K
Published by: user_K on April 27, 2010 11:32Hi there, the easiest way is to the LTS himself. Double-click your LTS, go to the tab with the column mappings. Make sure you have checked "show no mapped" column.
You should see your new dummy column in the list, in the central part of mapping (IE not the right) just enter 0, or launch the expression editor and enter 0 in there.
simple! -
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
-
Hi gurus,
Left outer join:
-------------------
Select * from A LEFT OUTER JOIN B on A.col = B.col;
by definition, a left outer join brings the rows that match the join condition and lines not corresponding to table A.
My question here is "corresponding to B and no matching rows in A" is that nothing, but... SELECT * FROM A;
can someone pls clarity...
Thank you.
Imagine that you had:
TableA
COLUMN1 COLUMN2
'A' 1
'B' 2
'C' 3
TABLEB
COLUMN1 COLUMN2
'A' 'X1'
'A' 'X2'
'B' 'Y'
'D' 'Z'
SELECT * FROM TABLEA;
A 1
B 2
C 3
Now, if you want to join (first column is either in table A or B, (deuxieme from tableA, third table B)
SELECT * FROM TABLEA A JOIN TABLEB B ON (A.COLUMN1 = B.COLUMN1)
A 1 X 1
A 1 X 2
B 2 Y
SELECT * FROM TABLE LEFT B EXTERNAL ON (A.COLUMN1 = B.COLUMN1) JOIN TABLE
A 1 X 1
A 1 X 2
B 2 Y
C 3 {null}
SELECT * FROM TABLE A TABLE RIGHT OUTER JOIN B (A.COLUMN1 = B.COLUMN1)
A 1 X 1
A 1 X 2
B 2 Y
D {null} Z
SELECT * FROM TABLE A TABLE FULL OUTER JOIN B (A.COLUMN1 = B.COLUMN1)
A 1 X 1
A 1 X 2
B 2 Y
C 3 {null}
D {null} Z
HTH
Maybe you are looking for
-
How can I put a GMail shortcut on my desktop?
I'm trying to put a shortcut to Gmail on my desktop and can not find the place where or how to do it. Any ideas?
-
Need print drivers for an OfficeJet 7610 for R2 in Windows 2008 Server
I need print drivers for an OfficeJet 7610 for R2 in Windows 2008 Server. The pilot to feel that you get when download you from hp.com are for XP and Vista Window7. The error message says I have to update my Windows 2008 Server R2 to XP, Windows7 a
-
Have an A1-810 Iconia. Don't know how to access the books that are on the card inside.
I just got an A10810 Iconia & there is already an SD card in there with books for me to read, but I don't know how to access. Went to the Queue Manager & can even get so far as to see the list of books, but how do I actually access each book to read?
-
Cannot delete the video not supported rocket
I was able to use MSC to convert a mpg file and transfer it to my rocket. But when I tried to watch it, I got an error message 'Unsupported Video' and the file closed. How to remove the file? I can't use the submenu in playback mode button, because t
-
I have a scheduled task that runs perfectly in Windows XP Pro, but the same task in Windows 7 returns a '0 x 2' under 'run last result. " According to the command of the command line, "net helpmsg 2 ', '0 x 2' is equivalent to"the system cannot find