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".
I have inherited a query that union alls 2 select statements, I added a further field to one of the select statements ( a date field). However I need to add another dummy field to the 2nd select statement so the union query marries up I have tried to do this by simply adding a
select 'date_on' to add a field called date on populated by 'date_on' (the name of the column in the first query)
however when I run the union query i get the error Ora-01790 expression must have same datatype as corresponding expression.
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]....
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
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.
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%');
I have a SQL query where I am making UNION of two select statements. The table that I am joining in each select statement have indexes defined for those tables.
Now the UNION of the two select statements again in enclosed in an inline view , from which I fetching my final field values.
The select statements inside the inline view returns huge number of row (like 50 million rows).
The whole query fails with time out.
How can I optimize this query further?
Is there a way to pass Oracle Hints so that Oracle uses indexes?
I am making a report in hrd regarding gross, deduction and there difference. I hv an attribute in the table as indicator whose value is addition and deduction. i want the sum of both in two diff column in a single rep. i want the report dept wise.
but i m getting fatal error at run time. which i don't understand.
I have a SQL query where I am making UNION of two select statements. The table that I am joining in each select statement have indexes defined for those tables.
Now the UNION of the two select statements again in enclosed in an inline view , from which I fetching my final field values.
The select statements inside the inline view returns huge number of row (like 50 million rows).
The whole query fails with time out.
Is there a way to pass Oracle Hints so that Oracle uses indexes?
I have the following Union All query. It throws the following error in SQL plus
ERROR at line 27: ORA-01789: query block has incorrect number of result columns
After doing some google for the above error it suggests there are incorrect number of columns in the Union All query.I could not figure out the exact location well SQl Plus says error is on line 27 at the first opening bracket like
- 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?
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';
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?
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 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.