Join or union or both
hi experts,
i am newbie, please help me with my sql query
table1
id X
1 1
2 1
3 1
1 1
3 1
table2
id Y
1 1
2 1
4 1
5 1
2 1
required output
id X Y
1 2 1
2 1 2
3 2 0
4 0 1
5 0 1
my following query produces wrong output, please help me to correct/rewrite it
select id, count(X) from table1 group by id, X
union
select id, count(Y) from table1 group by id, X
many thanks
Raj
Note the name of this forum is "SQL Developer *(Not for general SQL/PLSQL questions)*", so only for issues with the SQL Developer tool. Please post these questions under the dedicated {forum:id=75} forum only (so nor Reports).
Regards,
K.
Similar Messages
-
Strange behaviour of view based on several tables join with union all
Dear fellows we r facing a strange problem we have a view based on several tables joined by union all ,when we issue an ordered query on date,rows returned are unusually different than they should be .
Is oracle has some special behaviour for view based on union all ?
I m using oracle 8.1.6 on windows 2000
Kashif SohailDid you ever solve this problem? I have two select statements based on 4 tables and 3 views using about 5 more tables. When I execute each select individually I get exactly what is expected. When I UNION ALL both selects together, I get "no rows returned", however when I UNION them I get exactly what is expected. I should get the same answer for both UNION ALL and UNION. The two select statements are identical, except for one column where I changed the constant to be different. Any thoughts?
-
Hi Mates.
Could any one tell me the Basic difference between Joins and Unions . I know InfoSet contain joins and Multiproviders contains the unions.
Regards.
harryHi Harry,
Let suppose you had two table TAB1 = 10 records and TAB2 = 30.
If you are using the left join based on TAB1 for TAB2 then you will get only 10 only.
If you are using the inner join between tab1 and tab2 then you will get only the combination of records only...(less records)
if you are using the union between the two tables then you will get totaly 40 records.
Regards,
PRK
Message was edited by: PRK -
SQL - JOIN using UNION ?? UNION using JOIN ?? with example!
I was asked this question during one of my interviews. Can you do JOIN using UNION keyword? Can you do UNION using JOIN keyword?
That is -
1. I should get same output as JOIN without using JOIN keyword, but using UNION Keyword?
2. I should get same output as UNION without using UNION keyword, but using JOIN Keyword?
Can you give me an example of how to do this if possible?Hi,
Welcome to the forum!
user13067794 wrote:
I was asked this question during one of my interviews. Can you do JOIN using UNION keyword? Can you do UNION using JOIN keyword?The correct answer to those questions is: Why would you want to? All versions of Oracle (and probably any other database product) provide JOIN to do certain things and UNION to do other things. Why not use those features the way they were designed to be used? Even if it is possible to do what you ask, it's going to be more complicated and less efficient.
If you really must:
That is -
1. I should get same output as JOIN without using JOIN keyword, but using UNION Keyword? You can select the relevant columns from each table, and NULLs for all the columns from other tables, in a UNION query. Then you can use GROUP BY or analytic functions to combine data from different rows. For example, this JOIN:
SELECT d.dname
, e.mgr
FROM scott.dept d
JOIN scott.emp e ON d.deptno = e.deptno
;could be written using UNION, but no JOIN, like this:
WITH union_data AS
SELECT deptno
, dname
, NULL AS empno
, NULL AS mgr
FROM scott.dept
UNION ALL
SELECT deptno
, NULL AS dname
, empno
, mgr
FROM scott.emp
, quasi_join AS
SELECT MAX (dname) OVER (PARTITION BY deptno) AS dname
, mgr
, empno
FROM union_data
SELECT dname
, mgr
FROM quasi_join
WHERE empno IS NOT NULL
;Depending on your tables and your requirements, you might be able to do something a little simpler.
2. I should get same output as UNION without using UNION keyword, but using JOIN Keyword?A FULL OUTER JOIN is similar to UNION.
This UNION query:
SELECT dname AS txt
FROM scott.dept
UNION
SELECT TO_CHAR (mgr) AS txt
FROM scott.emp
;Can be written like this, using JOIN but no UNION:
SELECT DISTINCT
NVL2 ( e.empno
, TO_CHAR (e.mgr)
, d.dname
) AS txt
FROM scott.dept d
FULL OUTER JOIN scott.emp e ON 1 = 2
user13067794 wrote:I too don't any example as such, but I am thinking on this line -
Select a.x, b.y
from a,b
where a.key=b.key and sal<5000
UNION
Select a.x, b.y
From a,b
Where a.key=b.key and sal>7000
can we get same result using JOIN?That's a very special case. You can get the same results without using UNION like this:
Select distinct
a.x
, b.y
from a
, b
where a.key = b.key
and ( sal < 5000
OR sal > 7000
Can we do something similar using UNION without using JOIN keyword??What you posted does not use the JOIN keyword.
To get the same results without using a join (either with or without the JOIN keyword), you can use UNION together with aggregate or analytic functions, as I showed earlier.
Edited by: Frank Kulash on Jul 5, 2011 9:01 PM -
Both equii join and natural join are equall.will both display same output
both equii join and natural join are equall.will both display same
output?Hi ,
What is preventing you to do a small test and check yourself?
See the below link.
http://psoug.org/reference/joins.html
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> CREATE TABLE parents (
2 person_id NUMBER(5),
3 adult_name VARCHAR2(20),
4 comments VARCHAR2(40))
5 PCTFREE 0;
Table created.
SQL>
SQL> CREATE TABLE children (
2 parent_id NUMBER(5),
3 person_id NUMBER(5),
4 child_name VARCHAR2(20),
5 comments VARCHAR2(40))
6 PCTFREE 0;
Table created.
SQL>
SQL> INSERT INTO parents VALUES (1, 'Dan', 'So What');
1 row created.
SQL> INSERT INTO parents VALUES (2, 'Jack', 'Who Cares');
1 row created.
SQL> INSERT INTO children VALUES (1, 2, 'Anne', 'Who Cares');
1 row created.
SQL> INSERT INTO children VALUES (1, 1, 'Julia', 'Yeah Right');
1 row created.
SQL> INSERT INTO children VALUES (2, 1, 'Marcella', 'So What');
1 row created.
SQL> COMMIT;
Commit complete.
SQL>
SQL> SELECT adult_name, child_name
2 FROM parents NATURAL JOIN children;
ADULT_NAME CHILD_NAME
Jack Anne
Dan Marcella
SQL> select adult_name,child_name from parents a, children b
2 where a.person_id=b.person_id;
ADULT_NAME CHILD_NAME
Jack Anne
Dan Julia
Dan Marcella
SQL> ed
Wrote file afiedt.buf
1 select adult_name,child_name from parents a, children b
2* where a.person_id=b.parent_id
SQL> /
ADULT_NAME CHILD_NAME
Dan Anne
Dan Julia
Jack Marcella
SQL>Regards,
Avinash -
Question regarding Joins and Union
Hi All,
Here is the question:
I have two databases, on which I made a UNION to see both item codes and item names. The issue is that on one database I have an item with the same code than the other, but due human error, on the other database, I have the same name but with an "s" or something like that.
What I need to do is, when I make a query, I want to see all item codes from both tables, but I want to see only the description from the db1.
How can I do this?
| db1 | db 2
--------------------------- | ------------------------- | ---------------------------
itemcode | ART001 | ART001
item name | Rock | RocksPavan Patil wrote:
In my select query I am using only one column (which is part of primary) while joining two base tables and one column of foreign key of other table to get data.
My query here is whether I have to make use of all the columns of the composite primary key and foreign key to get the values and after making use of this whether performance of the query will be improved ? (Presently my qyery is taking 6.24 mins).
This is not a question of performance but of what result you want. The result of joining on one column is logically quite different to joining on all of them. I strongly suspect that you will need to join on all three key columns to get a useful result - but that depends on what you are trying to achieve. -
Error while using Group By on 2 Querys joined by union
Hello Everyone
I have a situation where in one report i cannot group the data and in another report when i group the data i am unable to view subject area.
I Had a Complex Request from my client , i have to claculate a report based on 2 dimensions i.e i am calculating 2 measures from one dimension and other 3 measures from other dimension and then using UNION to join both the querys , for the same description the data is being displayed in 2 rows , then i i tried to combine both the querys from union and trying to select from those then i am getting the result and the problem is i am unable to access the subject area , its giving "Either you do not have permission to use the subject area within Answers, or the subject area does not exist." Error , i am unable to add prompts to these request
I want the investor Grants Row to be displayed in one Column , I am already using Group by in one of the querys.
Study Cost Approved Committed Earned Paid Balance
Investigator Grants 350,000.00 113,770.78 0.00 0.00 0.00
Investigator Grants 350,000.00 113,770.78 42,403.13 19,905.90 22,497.23
Labs 23,000.00 0.00 0.00 0.00 0.00
Study Drug 47,000.00 0.00 0.00 0.00 0.00
Other 0.00 0.00 0.00 0.00 0.00
Here is my query
SELECT "- Protocol"."Protocol #" saw_0, "- Protocol"."Working Title" saw_1, CURRENT_DATE saw_2, "- Administration"."Display Currency Code" saw_3, "- Protocol"."Managing Country" saw_4, "- Protocol".Country saw_5, "- Protocol"."Country OPS" saw_6, "- Protocol"."EU Country" saw_7, "- Protocol"."GCO Region" saw_8, "- Protocol"."GPB Region" saw_9, "- Administration"."Study Cost" saw_10, SUM (IfNull("- Budget and Payment Facts"."Protocol Cost Line Item Amount - Display CCY",0) BY "- Administration"."Study Cost" ) saw_11, SUM(IfNull("- Budget and Payment Facts"."Committed Amount - Display CCY",0) BY "- Administration"."Study Cost") saw_12, SUM(IfNull("- Budget and Payment Facts"."Actual Amount - Display CCY",0) BY "- Administration"."Study Cost") saw_13, SUM(IfNull("- Budget and Payment Facts"."Amount Paid (SP) - Display CCY",0) BY "- Administration"."Study Cost") saw_14, SUM(IfNull("- Budget and Payment Facts"."Actual Amount - Display CCY",0)-IfNull("- Budget and Payment Facts"."Amount Paid (SP) - Display CCY",0) BY "- Administration"."Study Cost") saw_15, CASE WHEN "- Administration"."Study Cost" = 'Other' THEN 1 END saw_16 FROM "SPECTRUM Reporting" WHERE ("- Administration"."Display Currency Code" = 'USD') AND ("- Protocol"."Protocol #" = 'P31248') UNION SELECT "- Protocol"."Protocol #" saw_0, "- Protocol"."Working Title" saw_1, CURRENT_DATE saw_2, "- Administration". "Display Currency Code" saw_3, "- Protocol"."Managing Country" saw_4, "- Protocol".Country saw_5, "- Protocol"."Country OPS" saw_6, "- Protocol"."EU Country" saw_7, "- Protocol"."GCO Region" saw_8, "- Protocol"."GPB Region" saw_9, "- Administration"."Study Cost" saw_10, IfNull("- Budget and Payment Facts"."Protocol Cost Line Item Amount - Display CCY",0) saw_11, IfNull("- Budget and Payment Facts"."Committed Amount - Display CCY",0) saw_12, 0.00 saw_13, 0.00 saw_14, 0.00 saw_15, CASE WHEN "- Administration"."Study Cost" = 'Other' THEN 1 END saw_16 FROM "SPECTRUM Reporting" WHERE ("- Protocol"."Protocol #" = 'P31248') AND ("- Administration". "Display Currency Code" = 'USD') ORDER BY saw_16 DESC
Any help is appreciated ..!
~SrixHere is the query i used to group the data but i cannot access Answers with this query
SELECT saw_0 saw_0, saw_1 saw_1, saw_2 saw_2, saw_3 saw_3, saw_4 saw_4, saw_5 saw_5, saw_6 saw_6, saw_7 saw_7, saw_8 saw_8, saw_9 saw_9, saw_10 saw_10, SUM(saw_11 BY saw_10) saw_11, SUM(saw_12 BY saw_10 ) saw_12, SUM(saw_13 BY saw_10) saw_13, SUM(saw_14 BY saw_10) saw_14, SUM(saw_15 BY saw_10) saw_15, saw_16 saw_16 FROM (SELECT "- Protocol"."Protocol #" saw_0, "- Protocol"."Working Title" saw_1, CURRENT_DATE saw_2, "- Administration"."Display Currency Code" saw_3, "- Protocol"."Managing Country" saw_4, "- Protocol".Country saw_5, "- Protocol"."Country OPS" saw_6, "- Protocol"."EU Country" saw_7, "- Protocol"."GCO Region" saw_8, "- Protocol"."GPB Region" saw_9, "- Administration"."Study Cost" saw_10, SUM (IfNull("- Budget and Payment Facts"."Protocol Cost Line Item Amount - Display CCY",0) BY "- Administration"."Study Cost" ) saw_11, SUM(IfNull("- Budget and Payment Facts"."Committed Amount - Display CCY",0) BY "- Administration"."Study Cost") saw_12, SUM(IfNull("- Budget and Payment Facts"."Actual Amount - Display CCY",0) BY "- Administration"."Study Cost") saw_13, SUM(IfNull("- Budget and Payment Facts"."Amount Paid (SP) - Display CCY",0) BY "- Administration"."Study Cost") saw_14, SUM(IfNull("- Budget and Payment Facts"."Actual Amount - Display CCY",0)-IfNull("- Budget and Payment Facts"."Amount Paid (SP) - Display CCY",0) BY "- Administration"."Study Cost") saw_15, CASE WHEN "- Administration"."Study Cost" = 'Other' THEN 1 END saw_16 FROM "SPECTRUM Reporting" WHERE ("- Administration"."Display Currency Code" = 'USD') AND ("- Protocol"."Protocol #" = 'P31248') AND ("- Payment"."Payment Number"="- Payment"."Related Payment Request Number")
UNION SELECT "- Protocol"."Protocol #" saw_0, "- Protocol"."Working Title" saw_1, CURRENT_DATE saw_2, "- Administration". "Display Currency Code" saw_3, "- Protocol"."Managing Country" saw_4, "- Protocol".Country saw_5, "- Protocol"."Country OPS" saw_6, "- Protocol"."EU Country" saw_7, "- Protocol"."GCO Region" saw_8, "- Protocol"."GPB Region" saw_9, "- Administration"."Study Cost" saw_10, IfNull("- Budget and Payment Facts"."Protocol Cost Line Item Amount - Display CCY",0) saw_11, IfNull("- Budget and Payment Facts"."Committed Amount - Display CCY",0) saw_12, 0.00 saw_13, 0.00 saw_14, 0.00 saw_15, CASE WHEN "- Administration"."Study Cost" = 'Other' THEN 1 END saw_16 FROM "SPECTRUM Reporting" WHERE ("- Administration"."Display Currency Code" = 'USD') AND ("- Protocol"."Protocol #" = 'P31248')) T GROUP BY saw_0, saw_1, saw_2, saw_3, saw_4, saw_5, saw_6, saw_7, saw_8, saw_9, saw_10 , saw_11, saw_12, saw_13, saw_14, saw_15, saw_16 ORDER BY saw_0, saw_1, saw_2, saw_3, saw_4, saw_5, saw_6 -
Spatial join like UNION in ArcToolbox
I loaded two polygon-shapefiles in Oracle Spatial. Now I'd like to make a spatial overlay on these two sets of geometries, which has to work like the UNION-analysis in ArcToolbox. This means that the result of the overlay must keep all the separate geometries, not just one geometry (like SDO_UNION). For each resulting polygon I want to know the ID from the original polygons.
How can I do this?
I was thinking of a combination of the SDO_INTERSECTION and the SDO_XOR functions, but do these functions also work for sets of geometries, or just for a pair of geometries?
Thanks,
Anjaok, now i understand. your query may work. the where is searching the intersecting geometries each to another. that looks good. your intersection/difference is searching the result out of your where.
I see, you want to have the b geometry that is not covered by a and vice versa and also the union geometrie of both as new geometrie?
i think your way is ok.
i tried following - your idea has brought me to another implementation i_'Ve forgot for 2 months :(
-- Create table
drop table POLYTABLE1
drop table POLYTABLE2
create table POLYTABLE1
ID NUMBER(12),
GEOMETRY MDSYS.SDO_GEOMETRY
create table POLYTABLE2
ID NUMBER(12),
GEOMETRY MDSYS.SDO_GEOMETRY
INSERT INTO POLYTABLE1 (ID,GEOMETRY) VALUES(1,
MDSYS.SDO_GEOMETRY(
2003
,NULL
,NULL
,MDSYS.SDO_ELEM_INFO_ARRAY(1,1003,1)
,MDSYS.SDO_ORDINATE_ARRAY(1,1,3,1,3,2,2,1,1,1)
INSERT INTO POLYTABLE2 (ID,GEOMETRY) VALUES(2,
MDSYS.SDO_GEOMETRY(
2003
,NULL
,NULL
,MDSYS.SDO_ELEM_INFO_ARRAY(1,1003,1)
,MDSYS.SDO_ORDINATE_ARRAY(2,1,4,1,4,2,2,2,2,1)
insert into user_sdo_geom_metadata values ('POLYTABLE1','GEOMETRY',
MDSYS.SDO_DIM_ARRAY(
MDSYS.SDO_DIM_ELEMENT('X',0,10,0.05)
,MDSYS.SDO_DIM_ELEMENT('Y',0,10,0.05)
,NULL)
insert into user_sdo_geom_metadata values ('POLYTABLE2','GEOMETRY',
MDSYS.SDO_DIM_ARRAY(
MDSYS.SDO_DIM_ELEMENT('X',0,10,0.05)
,MDSYS.SDO_DIM_ELEMENT('Y',0,10,0.05)
,NULL)
create index i_geo_ptab1 on POLYTABLE1 (geometry) indextype is MDSYS.SPATIAL_INDEX
create index i_geo_ptab2 on POLYTABLE2 (geometry) indextype is MDSYS.SPATIAL_INDEX
SELECT a.id, b.id, SDO_GEOM.SDO_INTERSECTION(a.geometry, b.geometry, 0.05) intsxn_geom
FROM polytable1 b, polytable2 a
WHERE SDO_RELATE(a.geometry, b.geometry, 'mask=anyinteract')='TRUE'
UNION ALL
SELECT a.id, b.id, SDO_GEOM.SDO_DIFFERENCE(b.geometry, a.geometry, 0.05) intsxn_geom
FROM polytable2 b, polytable1 a
WHERE SDO_RELATE(a.geometry, b.geometry, 'mask=anyinteract')='TRUE'
UNION ALL
SELECT a.id, b.id, SDO_GEOM.SDO_DIFFERENCE(a.geometry, b.geometry, 0.05) intsxn_geom
FROM polytable2 b, polytable1 a
WHERE SDO_RELATE(a.geometry, b.geometry, 'mask=anyinteract')='TRUE'
the results are very interesting... i think: FALSE!! I am using a Oracle Database 10g Enterprise Edition Release 10.1.0.4.0...
can u compare with my reults?
SQL> SELECT a.id, b.id, SDO_GEOM.SDO_INTERSECTION(a.geometry, b.geometry, 0.05) intsxn_geom
2 FROM polytable1 b, polytable2 a
3 WHERE SDO_RELATE(a.geometry, b.geometry, 'mask=anyinteract')='TRUE'
4 UNION ALL
5 SELECT a.id, b.id, SDO_GEOM.SDO_DIFFERENCE(b.geometry, a.geometry, 0.05) intsxn_geom
6 FROM polytable2 b, polytable1 a
7 WHERE SDO_RELATE(a.geometry, b.geometry, 'mask=anyinteract')='TRUE'
8 UNION ALL
9 SELECT a.id, b.id, SDO_GEOM.SDO_DIFFERENCE(a.geometry, b.geometry, 0.05) intsxn_geom
10 FROM polytable2 b, polytable1 a
11 WHERE SDO_RELATE(a.geometry, b.geometry, 'mask=anyinteract')='TRUE';
2 1 SDO_GEOMETRY(2003, NULL, NULL, SDO_ELEM_INFO_ARRAY(1, 1003, 1), SDO_ORDINATE_ARRAY(2, 1, 3, 1, 3, 2, 2, 1))
1 2 SDO_GEOMETRY(2007, NULL, NULL, SDO_ELEM_INFO_ARRAY(1, 1003, 1, 11, 1003, 1), SDO_ORDINATE_ARRAY(3, 1, 4, 1, 4, 2, 3, 2, 3, 1, 2, 2, 2, 1, 3, 2, 2, 2))
1 2
! this also doesn't work correct with difference set to 1 (in metadata and geoemetry)!
Message was edited by:
Andreas Brodkorb -
Better than Self Join or Union
I have multiple tables where the result set for a query is one row, I need it to be multiple rows.
select * from EXT_MO_ALLOCATION
Gets me
What I need is
I'm getting this by using this query - which seems very messy to me
select MOAllocation_Key1,MOAllocation_161_Quantity1,MOAllocation_162_SONumber1
from EXT_MO_Allocation
where MOAllocation_Key1 = 'MO522825'
UNION
select MOAllocation_Key1,MOAllocation_164_Quantity2,MOAllocation_165_SONumber2
from EXT_MO_Allocation
where MOAllocation_Key1 = 'MO522825'
UNION
select MOAllocation_Key1,MOAllocation_167_Quantity3,MOAllocation_168_SONumber3
from EXT_MO_Allocation
where MOAllocation_Key1 = 'MO522825'
UNION
select MOAllocation_Key1,MOAllocation_170_Quantity4,MOAllocation_171_SONumber4
from EXT_MO_Allocation
where MOAllocation_Key1 = 'MO522825'
Is there a better / more efficient way to do this?
Thanks;with cte As
(Select 1 As Number
Union All
Select Number+1 As Number From cte Where Number < 4)
select MOAllocation_Key1,
Case When Number = 1 Then MOAllocation_161_Quantity1
When Number = 2 Then MOAllocation_164_Quantity2
When Number = 3 Then MOAllocation_167_Quantity3
When Number = 4 Then MOAllocation_170_Quantity4
End
Case When Number = 1 Then MOAllocation_162_SONumber1
When Number = 2 Then MOAllocation_165_SONumber2
When Number = 3 Then MOAllocation_168_SONumber3
When Number = 4 Then MOAllocation_171_SONumber4
End
from EXT_MO_Allocation
Cross Join cte
where MOAllocation_Key1 = 'MO522825'
The above query will retrieve the row only once. Your Union query will retrieve the row 4 times. So this will be more efficient. Whether it makes a noticeable difference depends. For example if you have a unique index or primary key
constraint or unique constraint on MOAllocation_Key1, you will see essentially no difference. On the other hand, if you have to scan an entire table of millions of rows to find that particular row, scanning the table once will be much faster than scanning
it 4 times.
Tom -
Repalcing UNIOn with full outer Join
I have a query wihch looks like ,
select colA,colB ,colC, coldD from A,B,C,D
where (some join conditions)
union
select colA,colB ,colC, NULL from A,B,C
where (some join conditions)
This query is posing us serious performance issues and we want to tune the query.
SO to remove the UNION operator we want to use FULL JOIN.
Can you please let us know how to frame the full outer join in the above query,so that the result set intact.
Thanks MuchHere goes my first query that uses UNION :
SELECT from_it.seq_routing,
from_it.milestone_routing_dt,
from_it.milestone_type_desc,
to_it.seq_routing,
to_it.milestone_routing_dt,
to_it.milestone_type_desc,
to_it.delay_flag,
to_it.acceptable_delay_flag,
TAB_A.calendar_minutes, TAB_A.business_minutes,
TAB_A.due_date, TAB_A.late_minutes,
TAB_A.delay_concat_comments,TAB_C.TAB_C_key,
TAB_C.pcd,TAB_C.ssn,
mmp.MEASURE_NAME,
api.METRICS_PARAMETER_KEY,
api.METRICS_PARAMETER_PRODUCT_KEY,
crt.JUSTIFICATION_CD,
crt.JUSTIFICATION_DESC,
crt.ROUTING_USER_SITE_DESC
FROM TAB_A, TAB_B from_it, TAB_B to_it,
TAB_C, TAB_E,TAB_D mmp,TAB_F api, TAB_G crt
WHERE from_it.TAB_B_key =
TAB_A.from_TAB_B_key
AND to_it.TAB_B_key =
TAB_A.to_TAB_B_key
ANDTAB_C.TAB_C_key = from_it.TAB_C_key
andTAB_C.TAB_C_key = to_it.TAB_C_key
and TAB_E.pck =crt.pck
and to_it.SEQ_ROUTING =crt.SEQ_ROUTING
and TAB_E.pcd =TAB_C.pcd
and TAB_E.ssn =TAB_C.ssn
andTAB_C.END_DT = TO_DATE('12/31/9999', 'MM/DD/YYYY')
and TAB_A.METRICS_MEASURE_KEY =mmp.METRICS_MEASURE_KEY
andapi.END_DT = TO_DATE('12/31/9999', 'MM/DD/YYYY')
andTAB_C.TAB_C_key =api.TAB_C_KEY
andapi.PARAMETER_TYPE = 'IN'
and TAB_A.end_dt = TO_DATE('12/31/9999', 'MM/DD/YYYY')
and CRT.end_dt = TO_DATE('12/31/9999', 'MM/DD/YYYY')
UNION
SELECT from_it.seq_routing,
from_it.milestone_routing_dt,
from_it.milestone_type_desc,
to_it.seq_routing,
to_it.milestone_routing_dt,
to_it.milestone_type_desc,
to_it.delay_flag,
to_it.acceptable_delay_flag,
TAB_A.calendar_minutes, TAB_A.business_minutes,
TAB_A.due_date, TAB_A.late_minutes,
TAB_A.delay_concat_comments,TAB_C.TAB_C_key,
TAB_C.pcd,TAB_C.ssn,
mmp.MEASURE_NAME,
api.METRICS_PARAMETER_KEY,
api.METRICS_PARAMETER_PRODUCT_KEY,
NULL, NULL, NULL
FROM TAB_A, TAB_B from_it, TAB_B to_it,
TAB_C, TAB_E,TAB_D mmp,TAB_F api
WHERE from_it.TAB_B_key =
TAB_A.from_TAB_B_key
AND to_it.TAB_B_key =
TAB_A.to_TAB_B_key
ANDTAB_C.TAB_C_key = from_it.TAB_C_key
andTAB_C.TAB_C_key = to_it.TAB_C_key
and TAB_E.pcd =TAB_C.pcd
and TAB_E.ssn =TAB_C.ssn
andTAB_C.END_DT = TO_DATE('12/31/9999', 'MM/DD/YYYY')
and TAB_A.METRICS_MEASURE_KEY =mmp.METRICS_MEASURE_KEY
andapi.END_DT = TO_DATE('12/31/9999', 'MM/DD/YYYY')
andTAB_C.TAB_C_key =api.TAB_C_KEY
andapi.PARAMETER_TYPE = 'IN'
and to_it.SEQ_ROUTING is null
and TAB_A.end_dt = TO_DATE('12/31/9999', 'MM/DD/YYYY')
And the one with OUTER JOIN used :
SELECT from_it.seq_routing,
from_it.milestone_routing_dt,
from_it.milestone_type_desc,
to_it.seq_routing,
to_it.milestone_routing_dt,
to_it.milestone_type_desc,
to_it.delay_flag,
to_it.acceptable_delay_flag,
TAB_A.calendar_minutes, TAB_A.business_minutes,
TAB_A.due_date, TAB_A.late_minutes,
TAB_A.delay_concat_comments,TAB_C.TAB_C_key,
TAB_C.pcd,TAB_C.ssn,
mmp.MEASURE_NAME,
api.METRICS_PARAMETER_KEY,
api.METRICS_PARAMETER_PRODUCT_KEY,
crt.JUSTIFICATION_CD,
crt.JUSTIFICATION_DESC,
crt.ROUTING_USER_SITE_DESC
FROM TAB_A JOIN
TAB_B from_it
on from_it.TAB_B_key =
TAB_A.from_TAB_B_key
and TAB_A.end_dt = TO_DATE('12/31/9999', 'MM/DD/YYYY')
JOIN
TAB_B to_it
ON to_it.TAB_B_key =
TAB_A.to_TAB_B_key
JOINTAB_C
ONTAB_C.TAB_C_key = from_it.TAB_C_key
ANDTAB_C.TAB_C_key = to_it.TAB_C_key
andTAB_C.END_DT = TO_DATE('12/31/9999', 'MM/DD/YYYY')
JOINTAB_D mmp
ON TAB_A.METRICS_MEASURE_KEY =mmp.METRICS_MEASURE_KEY
JOIN TAB_E
ON TAB_E.pcd =TAB_C.pcd
and TAB_E.ssn =TAB_C.ssn
-- and TAB_E.ssn = 'PFEARG'
JOINTAB_F api
ON TAB_C.TAB_C_key =api.TAB_C_KEY
andapi.PARAMETER_TYPE = 'IN'
andapi.END_DT = TO_DATE('12/31/9999', 'MM/DD/YYYY')
LEFT -
Oracle doc inconsistent on materialize view with union all and self joins
First of all, I can't seem to create a materialized view containing self-joins AND union all. Is it possible?
I checked Oracle 9i (my version: PL/SQL Release 9.2.0.4.0 - Production) documentation and I get different answers (or so it seems to me).
First I saw this: "The COMPATIBILITY parameter must be set to 9.0 if the materialized aggregate view has inline views, outer joins, self joins or grouping sets and FAST REFRESH is specified during creation..."
Did you see the part about 'self joins' in there? I did and I was pumped because that seems to say that you CAN have 'self joins' (and my compatibility is 9.2...)
BUT
In the very same document I also found "Oracle does not allow self-joins in materialized join views." (rage)
You can see the document I am speaking of here: http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96520/mv.htm#574889
Whenever I try to create the mview I get the following error. (
In any caseORA-01446 cannot select ROWID from view with DISTINCT, GROUP BY, etc.First of all, I can't seem to create a materialized view containing self-joins AND union all. Is it possible?
I checked Oracle 9i (my version: PL/SQL Release 9.2.0.4.0 - Production) documentation and I get different answers (or so it seems to me).
First I saw this: "The COMPATIBILITY parameter must be set to 9.0 if the materialized aggregate view has inline views, outer joins, self joins or grouping sets and FAST REFRESH is specified during creation..."
Did you see the part about 'self joins' in there? I did and I was pumped because that seems to say that you CAN have 'self joins' (and my compatibility is 9.2...)
BUT
In the very same document I also found "Oracle does not allow self-joins in materialized join views." (rage)
You can see the document I am speaking of here: http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96520/mv.htm#574889
Whenever I try to create the mview I get the following error. (
In any caseORA-01446 cannot select ROWID from view with DISTINCT, GROUP BY, etc. -
How to avoid Duplicate Records while joining two tables
Hi,
I am trying to join three tables, basically two tables are same one is like history table, so I wrote a query like
select
e.id,
e.seqNo,
e.name,
d.resDate,
d.details
from employees e,
((select * from dept)union(select * from dept_hist)) d
join on d.id=e.id and e.seqno=d.seqno
but this returing duplicate records.
Could anyone please tell me how to avoid duplicate records of this query.Actually it is like if the record is processed it will be moved to hist table, so both table will not have same records and I need the record from both the tables so i have done the union of both the tables, so d will have the union of both records.
But I am getting duplicate records if even I am distinct. -
Mini Displayport to S-Video using two joined DVI adaptors?
I have a 13" MacBook with the mini displayport. I am attempting to connect it to an external display (Samsung plasma monitor). I have connected two adaptors together: (minidisplay--DVI) + (DVI--Video), and have tried running both video and S-video cables from that into my Samsung, without success.
The MacBook does not seem to recognize that anything is connected to the mini displayport; the MacBook screen goes blue very briefly when I plug or unplug, but other than that there is no indication. I have tried powering off, sleeping/waking, and plugging/unplugging on both ends. I know the video input port on the Samsung is good (I believe the S-video port is good but can't prove it), and I know the video cable is good.
Has anyone had success with this setup? Does joining the two adaptors (both purchased from Apple) create a problem? Or is it set up correctly and an indication that one or both of the adaptors is malfunctioning? Any suggestions appreciated.
(Note: yes, there is a VGA port on the Samsung, but it's wall mounted and virtually inaccessible. I am using video inputs on side of device).With the advent of the Aluminum MacBook, Apple stopped supporting video and S-video out. You will either need to use VGA or else something like this:
http://www.monoprice.com/products/product.asp?cid=101&cp_id=10114&cs_id=1011407&pid=4724&seq=1&format=2 -
[39008] Logical dimension table has a source that does not join to any fact
Dear reader,
After deleting a fact table from my physical layer and deleting it from my business model I'm getting an error: [39008] Logical dimension table TABLE X has a source TABLE X that does not join to any fact source. I do have an other fact table in the same physical model and in the same business model wich is joined to TABLE X both in the physical and business model.
I cannot figure out why I'm getting this error, even after deleting all joins and rebuilding the joins I'm getting this error. When I look into the "Joins Manager" these joins both in physical as well as logical model do exist, but with consistency check it warns me about [39008] blabla. When I ignore the warning and go to answers and try to show TABLE X (not fact, but dim) it gives me the following error.
Odbc driver returned an error (SQLExecDirectW).
Error Details
Error Codes: OPR4ONWY:U9IM8TAC:OI2DL65P
State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 14026] Unable to navigate requested expression: TABLE X.column X Please fix the metadata consistency warnings. (HY000)
SQL Issued: SELECT TABLE X.column X saw_0 FROM subject area ORDER BY saw_0
There is one *"special"* thing about this join. It is a complex join in the physical layer, because I need to do a between on dates and a smaller or equal than current date like this example dim.date between fact.date_begin and fact.date_end and dim.date <= current_date. In the business model I've got another complex join
Any help is kindly appreciated!Hi,
Have you specified the Content level of the Fact table and mapped it with the dimension in question? Ideally this should be done by default since one of the main features of the Oracle BI is its ability to determine which source to use and specifying content level is one of the main ways to achieve this.
Another quick thing that you might try is creating a dimension (hierarchy) in case it is not already present. I had a similar issue few days back and the warning was miraculously gone by doing this.
Regards -
Select query with UNION clause in database adapter
Friends,
I have got a SQL query with two UNION clause withing it. like
select a,b,c
from a
union
select a,b,c
from b
The schema generated is like below in sequence
<element>a</element>
<element>b</element>
<element>c</element>
<element>a</element>
<element>b</element>
<element>c</element>
So, the columns from different select queries joined with UNION clause are all appeared in schema instead of the distinct columns.
Is there any way around to solve this issue ? or will need to with DB function/procedure.I think I know what you are saying but your example doesn't make sense, your SQL should produce something like
I had to change a, b, c with elementA, elementB, elementC as a and b are reserved html tags.
<elementA>DateA</elementA>
<elementB>DataB</elementB>
<elementC>DataC</elementC>
...What is the result of the query when you run it in SQLPlus? Is it what you expect?
cheers
James
Maybe you are looking for
-
DataGrid - Create at runtime - How to Add Items??
I create a DataGrid at runtime and then and columns to it as need be. How Can I add items with the correct dataField if I don't if I don;t know this till runtime? In other word I'm having trouble constructing the Object to send to AddItem becase the
-
The cursor won't focus when I open a new tab
I've read through multiple threads on this in attempt to not waste people's time with a silly question. After trying the myriad of ideas, the problem persists. When I open a new tab whether with about:newtab or about:blank, the cursor does not focus
-
Hi I have a requirment for getting wbs element in SRM system (SRM 3.0 ) from R/3 4.6c based on status of wbs element like TECO, ISBD, CLSD. Please can anybody suggest any standard FM / Metabapi exist in SRM for resolving this issue. Regards MJT
-
I have an account in Apple Astor was not able to access it, please help me in this matter
I have an account in Apple Astor was not able to access it, please help me in this matter <E-mail Edited by Host>
-
How to getr StackTraces of all server threads
Hi all, I've tried to get stacktraces for all threads on Sun Java Application Server V8. I followed the manual. I tried CTRL+\ in verbose mode. But i think i got only stack traces of some supporting java process, not of the whole server. So my questi