Below is my query Issue faced is that based on union I want to limit the result and does not want second query to give duplicate result as both queries deal with same table
SELECT TAB1.ID, TAB1.CRNCY_CODE, TAB2.SCHEME_CODE, DECODE( 'INFENG',CAST( '' AS VARCHAR(20)),
NVL(TAB2.ALT1_SCHEME_DESC,TAB2.SCHEME_DESC),TAB2.SCHEME_DESC),
TAB1.SUB_HEAD_CODE, DECODE( 'INFENG' ,CAST( '' AS VARCHAR(20)),NVL(TAB1.ALT1_SUB_HEAD_DESC ,
TAB1.SUB_HEAD_DESC),TAB1.SUB_HEAD_DESC)
[code]...
select null ID,null crncy_code,TAB2.SCHEME_CODE ,
NVL(TAB2.ALT1_SCHEME_DESC,TAB2.SCHEME_DESC),TAB2.SCHEME_DESC,null SUB_HEAD_CODE from TAB2 where TAB2.SCHEME_TYPE ='SCHEME1';
- returning from the procedure 2 ref cursors containing result set of 2 queries - returning from the procedure 1 ref cursor containing result set of that 2 queries as one (with UNION ALL)?
I have a query which has 5 unions, each clause of the union takes 1 hr to run and query results come back in 5 hrs, Is there any way I can make these clause to run in parallel?
I'm just trying to see if there is another way of doing this query without using a UNION. The only way I can see is using a UNION but maybe I'm missing something or a way to do it without a UNION.
Result:
Select any customer within the user_states table who lives in "MO" Select any customer within the user_cars table who lives in "MO" and has a "White" car Select any customer within the user_plates table who lives in "MO" and has a plate of "A" or "B" Join to the user_names table to display the customers name
So, the result would be any customer who lives in "MO" who owns a "White" car and any customer who lives in "MO" who has a plate of "A" or "B".
Cant find any artice on what is better to use unpivot or union all. I can achive same results using either but cant decide what would be better. For example a table has columns:
Name 1, Phone1, Name 2, Phone 2. The result I want would be:
I've got function with combined sql statement (union all), how do I split it into two sql requests? This is to avoid time increasing of sql executing. IMHO good solution is to write two functions, how do you think?
I am new to SQL Oracle programming and have a question on a union query. I am trying to get results (example) for the following:
Org # Full_date Run_date 5 2/20/2012 2/20/2012 5 2/21/2012 2/21/2012 5 2/22/2012 null (there is not a record for this) 6 2/20/2012 2/20/2012 6 2/21/2012 null 6 2/22/2012 2/22/2012 7 2/20/2012 2/20/2012 7 2/21/2012 2/21/2012 7 2/22/2012 2/22/2012
The dw_time table would have the listing of all dates, (Full_date) and the dw_capacity_daily table would have the run_date. Here is my
select * from ( select distinct a.Organization_Nbr, d.full_date from CMBHS_DW.DW_ORGANIZATION a, cmbhs_DW.DW_Organization_Identifier b, cmbhs_DW.DW_Contract c, cmbhs_dw.dw_time d where a.ORGANIZATION_NBR = b.ORGANIZATION_NBR [code]....
How I can get the union result of 2 queries and put them in xml result, but I want each query to be in seperate xml element. I don t want to put 1 single xmlelement and do a From then construct a virtual table uniting the 2 subqueries
I mean I don t want something like the following:
(Select XMLAGG( XMLELEMENT("credit",
[Code]...
Except the 2nd alternative is not working I get error message: "SQL command not properly ended"
I have one scenario in which i want to write the sql,but not able to write correct qry,
tables 1-emp 2-emp_hist 3-dept 4-dept_hist.
i want to retrieve data from the emp and hist able based on some conditions,but if data is not present in emp and dept tables.then fetch data from emp_hist and dept_hist.I have written below qry which is working fine,but my prob is i want to provide my emp_id only one place. else i have to change my java code.
select * from emp,dept where emp.emp_id=dept.dept_id and emp_id=5 union select * from emp_hist,dept_hist where emp_hist.emp_id=dept_hist.dept_id and emp_id=5
I would like to SELECT these 3 hardcoded titles from DUAL, and have a blank line under each, on the output in this order from the SQL. But the result does not end up that way
SQL> set heading off; 1 select '#ENCODING WINDOWS-1252' from dual 2 union 3 select ' ' from dual 4 union 5 select 'Language Section EN-US' from dual 6 union 7 select ' ' from dual 8 union 9* select 'Catalog Section Title Date Source' from dual SQL> /
#ENCODING WINDOWS-1252 Catalog Section Title Date Source Language Section EN-US
- - - - - - - - - - - - - - - - -
Desired Output: #ENCODING WINDOWS-1252 Language Section EN-US Catalog Section Title Date Source
I am writing a query and I did get it to work but it shouldn't be this hard, I feel like I am doing something wrong, and there has to be a more elegent solution.
This query works:
SELECT a.d FROM ( SELECT S_ID a, LOOKUP_DESC d, S_CODE f FROM SSS JOIN LOOKUP ON S_CODE LIKE LOOKUP_CODE UNION ALL
[Code]...
I feel like I should be able to execute the query like this: This query doesn't work:
SELECT a.d FROM ( SELECT S_ID a, LOOKUP_DESC d, S_CODE f FROM SSS JOIN LOOKUP ON S_CODE LIKE LOOKUP_CODE
I have a requirement in SQL that I have to number each row. Hence I thought of using ROWNUM. But the sql query I'm using uses UNION operator. Hence I used like this
select a,b,rownum as 'field1' from table1 union select c,d,1 as 'field1' from table2
I have a view that contain multiple tables with ( UNION all ) clause , is there any way that if i query from this view I can explicitly specify the table that i need the data from ?
Let say i have view that contain salaries of 2011
Create view sals_2011 as select * from sals_jan2011 union all sals_feb2011 ..... union all select * from sals_dec2011.
if i issued select * from sals_2011 where emp_id >500 and date < 01-feb-2011 the explain plan show me that full tables and indexes are in processing, while i know that i need only to scan sal_jan2011, and of course it is taking much longer time than selecting from the original table only.
I am trying to display the results from 2 queries, one is supposed to display the count of the employees, per department, who win over the average of the entire company and the other one is supposed to display the count of the employees, per department, who win under the average of the entire company.
I used a UNION ALL, but all it does is merge the results from the ones that win over and under the average into one row, is there a way to separate them? I tried assigning names to each salary using AS but it only displays the first I put in.
sql Original - sql Code ( SELECT DE.DEPARTMENT_NAME, COUNT (EM.EMPLOYEE_ID) AS MAYORES FROM DEPARTMENTS DE, EMPLOYEES EM WHERE DE.DEPARTMENT_ID = EM.DEPARTMENT_ID AND EM.SALARY > (SELECT AVG(EM.SALARY) FROM EMPLOYEES EM) GROUP BY DE.DEPARTMENT_NAME [code].....
We have very large table having data more than 1000 millions rows. We divide this table into four physical tables say A, B, C and D. The physical horizontal partition of data of this original table is done based upon their business policy.
Each partitioned table has contained data of particular business entity. Further each table has partition and sub partitions based upon business rule.
We have to retrieve data from all these tables as follows:
select a1, a2, a3, a4, a5, a6 from A where < logical filter condition> union all select b1, b2, b3, b4, b5, b6 [code].....
We observed that above each query block execute in serial one after another and individual each query block capable to process data in parallel from respective table.
How does this above query able to execute each query block in parallel?
The DBAs have built 2 Materialized Views, which aggregates data in the fact tables at column C1 level
MAT_VIEW1 :SELECT C1_ID, SUM(SALE) SALES from FACTTABLE1 join LOOKUPTABLE on C1_ID MAT_VIEW2: SELECT C1_ID, SUM(SALE) SALE from FACTTABLE2 join LOOKUPTABLE on C1_ID
We are using an old BI tool that can ONLY generate Inline Views in these formats.
CASE1: select INL_VIEW.C1_ID ,LOOKUPTABLE.C1_NAME ,sum(SALE) SALE from (select C1_ID, C2_ID, null C3_ID, SALE from FACTTABLE1)INL_VIEW join LOOKUPTABLE on INL_VIEW.C1_ID = LOOKUPTABLE.C1_ID group by INL_VIEW.C1_ID, LOOKUPTABLE.C1_NAME
CASE2: select INL_VIEW.C1_ID ,LOOKUPTABLE.C1_NAME ,sum(SALE) SALE from (select C1_ID, null C2_ID, C3_ID, SALE from FACTTABLE2)INL_VIEW join LOOKUPTABLE on INL_VIEW.C1_ID = LOOKUPTABLE.C1_ID group by INL_VIEW.C1_ID, LOOKUPTABLE.C1_NAME
CASE3: select INL_VIEW.C1_ID ,LOOKUPTABLE.C1_NAME ,sum(SALE) SALE from ( select C1_ID, C2_ID, null C3_ID, SALE from FACTTABLE1 union all select C1_ID, C2_ID, null C3_ID, SALE from FACTTABLE2 )INL_VIEW join LOOKUPTABLE on INL_VIEW.C1_ID = LOOKUPTABLE.C1_ID group by INL_VIEW.C1_ID, LOOKUPTABLE.C1_NAME
Oracle 11g rewrites Case 1 and Case 2 to use the correct materialized views. But for case 3, it goes to the base fact tables 1 and 2. Is there a way to make oracle use the MVs even if there is a UNION ALL in the inline view? There is a 1:M Foreign Key relationship between LOOKUPTABLE.C1_ID and the 2 fact tables.
i have a union all query (two quiries i suppose) that runs fine and returns the results i am after.... when i try to use this query to create a view I get
SQL Command: CREATE OR REPLACE FORCE Failed: Warning: execution completed with warning
CREATE OR REPLACE FORCE VIEW "schema1"."name_of_view" ("column1", "column2", "column3") AS SELECT b.column1, a.column2, c.column3
select a.empno,a.ename,a.job, B.DNAME from scott.emp a,scott.dept b where ( a.ename like 'S%' and a.deptno=b.deptno) union select a.empno,a.ename,a.job, 'aaa' AS DNAME from scott.emp a,scott.dept b where ( a.ename like 'S%' and a.job not like 'SALES%');
now my code is using UNION ALL to get output as in table2 select col1,col1,'Segment1' col3,Segment1 col4 from table1 union all select col1,col1,'Segment2' col3,Segment2 from table1 union all select col1,col1,'Segment3' col3,Segment3 from table1
But the problem is the performance is realy bad.Is there any way i can do this without using union all? The time that take to execute this is not exceptable.