Combine tables with common data - union
Hi,
sorry if this has already been posted but I couldn't find a similar thread out there.
I have two small tables where there are duplicate parts. I'd like to combine the two into 1.
Table 1
Part_Num
Serialized_Part
Table 2
Part_Num
Hazardous_Part
a part can be both serialized and hazardous. I'd like to simply create a table
Final Table
Part_Num - distinct value combining tables.
Serialized_Part - value from table 1
Hazardous_Part - value from table 2
My SQL needs some work.
Thanks in advance,
--TD
Hi,
Welcome to the forum!
Whenever you have a question, it helps if you post a little sample data in a form people can use, for example:
CREATE TABLE Table_1
( Part_Num NUMBER (6) PRIMARY KEY
, Serialized_Part VARCHAR2 (10)
INSERT INTO table_1 (part_num, serialized_part) VALUES (1, 'Widget');
INSERT INTO table_1 (part_num, serialized_part) VALUES (2, 'Fubar');
CREATE TABLE Table_2
( Part_Num NUMBER (6) PRIMARY KEY
, Hazardous_Part VARCHAR2 (12)
INSERT INTO table_2 (part_num, hazardous_part) VALUES (2, 'Acid');
INSERT INTO table_2 (part_num, hazardous_part) VALUES (3, 'Knife');
CREATE TABLE Final_Table
( Part_Num NUMBER (6) PRIMARY KEY
, Serialized_Part VARCHAR2 (10)
, Hazardous_Part VARCHAR2 (12)
);Also post the results you want from that data. In this case, I think you want final_table, which starts with no rows, to contain this data when everything is finished:
. PART_NUM SERIALIZED HAZARDOUS_PA
1 Widget
2 Fubar Acid
3 KnifeHere's one way to get those results:
INSERT INTO final_table (part_num, serialized_part, hazardous_part)
WITH combined_data AS
SELECT part_num
, serialized_part
, NULL AS hazardous_part
FROM table_1
UNION
SELECT part_num
, NULL AS serialized_part
, hazardous_part
FROM table_2
SELECT part_num
, MIN (serialized_part) AS serialized_part
, MIN (hazardous_part) AS hazardous_part
FROM combined_data
GROUP BY part_num
;You had the right idea with UNION, but UNION may leave two rows with the same part_num. GROUP BY can combine any number of rows into one. Since, at most, one those rows will have a serialized_part, and, likewise, at most one of those rows will have a hazardous_part, then it doesn't matter if you use MIN or MAX to get that one value.
Similar Messages
-
Query on a table with indexed date field
I have a table with a date column which is indexed. If I run a query like "select column1 where date_field='20-JAN-04' for example it is fast and uses index.
If I run select column1 where date < '20-JAN-04' it is slow and doesnt use the index. I logged a TAR and Oracle told me that this is to be expected as not using the index in this case is the most effiecient way of doing the query.
Now my concept of an index is like the index of Yellow Pages(telephone directory) for example. In this example if I look for a name that is say "Halfords" or below, I can see all entries for Halfords and all the way to ZZZ in one block.
I just cant see , in a common sense way why Oracle wont use the index in this type of query.
GeorgeUsing the concept of a telephone directory is wrong. In a telephone directory you have all information order by the name. However in your table (if it is not an IOT) you don't have all information/rows ordered by your date_field. Rather think at the document "Oracle9i Database Concepts" and it's index.
Let's say you want to find all indexed words larger then "ISO SQL standard" (ok that doesn't make sense but it is just an example). So would it be faster to read the whole document or to lookup each word in the index and then read the entire page (Oracle block) to find the word.
It's not allways easy to know in advance if the query will be faster over the index or a full table scan. what you need to do is to well analyze (dbms_stats) the table and it's index, in most cases Oracle chooses the right way. You may also use the hint /*+ index(table_name index_name) */ and will see if it would be faster over the index or not.
A good document about that subject is:
http://www.ioug.org/tech/IOUGinDefense.pdf
HTH
Maurice -
How To Create Table with Static Data
JDEV 10.1.3
ADF BC
ADF Faces
I am trying to make some simple screen/screenflow diagrams to help flesh out some requirements. To do that, I need to make a table with static data that is not hooked up to a data source (because the data model has not yet been clearly defined, and I'm using the diagrams to help iterate the requirements).
Is it possible to create a table that shows static data (i.e. a set of rows that does not come from a model data source, but rather is hardcoded.)
If not, how does one create mock ups without actually implementing the data model?
Thank you.Deepak, what specifically in those 2 links from Amis are useful? Those 2 posts are about bind variables, not static list of values?
In response to the original poster, I'll attempt to help a little more.
In the 11g release you can create VOs based on a static list of values. However in your case on 10.1.3, the best method I've found is to create a VO based on a SELECT <columns> FROM DUAL statement. The columns then include your dummy data. If you need more than one row, simply UNION ALL a number of SELECT statements together.
What I haven't checked, is when you eventually transform the VO based on the SELECT DUAL statement into a VO based on an EO drawing real data from the database, is it an easy process? I recommend you try this out before committing to the approach above. Let us know how you go.
Regards,
CM. -
Web Analysis : populate the same table with multiple data sources
Hi folks,
I would like to know if it is possible to populate a table with multiple data sources.
For instance, I'd like to create a table with 3 columns : Entity, Customer and AvgCostPerCust.
Entity and Customer come from one Essbase, AvgCostPerCust comes from HFM.
The objective is to get a calculated member which is Customer * AvgCostPerCust.
Any ideas ?
Once again, thanks for your help.I would like to have the following output:
File 1 - Store 2 - Query A + Store 2 - Query B
File 2 - Store 4 - Query A + Store 4 - Query B
File 3 - Store 5 - Query A + Store 5 - Query B
the bursting level should be give at
File 1 - Store 2 - Query A + Store 2 - Query B
so the tag in the xml has to be split by common to these three rows.
since the data is coming from the diff query, and the data is not going to be under single tag.
you cannot burst it using concatenated data source.
But you can do it, using the datatemplate, and link the query and get the data for each file under a single query,
select distinct store_name from all-stores
select * from query1 where store name = :store_name === 1st query
select * from query2 where store name = :store_name === 2nd query
define the datastructure the way you wanted,
the xml will contain something like this
<stores>
<store> </store> - for store 2
<store> </store> - for store 3
<store> </store> - for store 4
<store> </store> - for store 5
<stores>
now you can burst it at store level. -
How to fill internal table with no data in debugging mode
Hi all,
I modified one existing program.Now I want to test it.I am not given test data.So in the middle of my debugging, I found that one internal table with no data.My problem is how to fill that internal table with few records in that debugging mode just as we change contents in debugging mode.If I want to proceed further means that internal table must have some records.
Please I dont know how to create test data so I am trying to create values temporarily in debugging mode only.
Thanks,
BalajiHi,
In the debugging do the following..
Click the Table button..
Double click on the internal table name..
Then in the bottom of the screen you will get the buttons like CHANGE, INSERT, APPEND, DELETE..
Use the APPEND button to insert records to the internal table..
Thanks,
Naren -
How to compare two rows from two table with different data
how to compare two rows from two table with different data
e.g.
Table 1
ID DESC
1 aaa
2 bbb
3 ccc
Table 2
ID DESC
1 aaa
2 xxx
3 ccc
Result
2Create
table tab1(ID
int ,DE char(10))
Create
table tab2(ID
int ,DE char(10))
Insert
into tab1 Values
(1,'aaa')
Insert
into tab1 Values
(2,'bbb')
Insert
into tab1 Values(3,'ccc')
Insert
into tab1 Values(4,'dfe')
Insert
into tab2 Values
(1,'aaa')
Insert
into tab2 Values
(2,'xx')
Insert
into tab2 Values(3,'ccc')
Insert
into tab2 Values(6,'wdr')
SELECT
tab1.ID,tab2.ID
As T2 from tab1
FULL
join tab2 on tab1.ID
= tab2.ID
WHERE
BINARY_CHECKSUM(tab1.ID,tab1.DE)
<> BINARY_CHECKSUM(tab2.ID,tab2.DE)
OR tab1.ID
IS NULL
OR
tab2.ID IS
NULL
ID column considered as a primary Key
Apart from different record,Above query populate missing record in both tables.
Result Set
ID ID
2 2
4 NULL
NULL 6
ganeshk -
Sample report for filling the database table with test data .
Hi ,
Can anyone provide me sample report for filling the database table with test data ?
Thanks ,
Abhi.hi
the code
data : itab type table of Z6731_DEPTDETAIL,
wa type Z6731_DEPTDETAIL.
wa-DEPT_ID = 'z897hkjh'.
wa-DESCRIPTION = 'computer'.
append wa to itab.
wa-DEPT_ID = 'z897hkjhd'.
wa-DESCRIPTION = 'computer'.
append wa to itab.
loop at itab into wa.
insert z6731_DEPTDETAIL from wa.
endloop.
rewards if helpful -
Select from 2 tables with common key and than left join(unique result)
Hi,
I have 2 tables that have a common id (Customer_id) and I have a third table which contain her key consist of 3 column ( Customer_id , rms_customer_id,billind_tree_id) and have the manager_name field
I am using a left join because not all the customers have a manager.
I need to take only the manager_name field from the left join but the problem is that I am not getting a unique name results because the customer_id is not the primary key(only part of )
so I have use the following :
left join
( select * from ACCOUNT_Manager am where
rms_customer_id <= all (select rms_customer_id from ACCOUNT_Manager am2 where
am2.customer_id = am.customer_id )) am
on c.ID = am.CUSTOMER_ID (C is one of the first 2 tables with the ID as key)
Is there anyway more efficient of doing it ?
ThanksPlease consider the following when you post a question. This would help us help you better
1. New features keep coming in every oracle version so please provide Your Oracle DB Version to get the best possible answer.
You can use the following query and do a copy past of the output.
select * from v$version 2. This forum has a very good Search Feature. Please use that before posting your question. Because for most of the questions
that are asked the answer is already there.
3. We dont know your DB structure or How your Data is. So you need to let us know. The best way would be to give some sample data like this.
I have the following table called sales
with sales
as
select 1 sales_id, 1 prod_id, 1001 inv_num, 120 qty from dual
union all
select 2 sales_id, 1 prod_id, 1002 inv_num, 25 qty from dual
select *
from sales 4. Rather than telling what you want in words its more easier when you give your expected output.
For example in the above sales table, I want to know the total quantity and number of invoice for each product.
The output should look like this
Prod_id sum_qty count_inv
1 145 2 5. When ever you get an error message post the entire error message. With the Error Number, The message and the Line number.
6. Next thing is a very important thing to remember. Please post only well formatted code. Unformatted code is very hard to read.
Your code format gets lost when you post it in the Oracle Forum. So in order to preserve it you need to
use the {noformat}{noformat} tags.
The usage of the tag is like this.
<place your code here>\
7. If you are posting a *Performance Related Question*. Please read
{thread:id=501834} and {thread:id=863295}.
Following those guide will be very helpful.
8. Please keep in mind that this is a public forum. Here No question is URGENT.
So use of words like *URGENT* or *ASAP* (As Soon As Possible) are considered to be rude. -
Creation of a table with static data(not a DB table)
Hi
I need to display a table with some static data in an OAF page. This table is not a DB table. It is like an HTML table
I have placed the following query
SELECT 'A1','B1' FROM DUAL UNION SELECT 'A2',B2' FROM DUAL in the VO. But it is returning a single row which is acting as the header of the table.
Can anyone help me to create the table with 2 rows inserted in it.
Thanks
Edited by: gsaxena on Aug 4, 2009 3:04 AM
Edited by: gsaxena on Aug 4, 2009 5:24 AMHi
Please execute your VO inside the CO of table region ,right now it is not getting executed,thats y it is giving just column names
use the following code PR method of CO
OAApplicationModule am = pageContext.getApplicationModule(webBean);
OAViewObject oav = (OAViewObject)am.findViewObject("XXVO");
oav.first();
let me know in case of any issue
thanx
Pratap -
Logical fact table with fragmented data sources with different dimensions
Hello.
I have a logical fact table with four logical table sources. Three of the LTS's share the same dimensions, but the fourth LTS has one dimension (called Dim_A) less. In the physical layer the dimension Dim_A is joined to the first three physical fact tables, but not to the fourth fact table (since it doesn't have that dimensionality). In the BMM layer the logical fact table is joines to the logical dimansion Dim_A.
When I run an analysis on this RPD the measures from the logical fact is aggregated correctly (union of all four table sources) as long as I doesn't include Dim_A, but as soon as I include dimension Dim_A I get the error message:
+State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 43113] Message returned from OBIS. [nQSError: 43119] Query Failed: [nQSError: 14052] Internal Error: Logical column Dim_A.Column_X has no physical sources that can be joined to the physical fact table source [Logical table sources (Priority=0): Fact_B.Fact_Y]. (HY000)+
I would like a solution where the analysis returns correctly aggregated measures also for the LTS with the "missing" dimension, but with a dimension value NULL for this LTS. Or something like this.
Is there a way to set this up in the RPD.
Thanks,
Henning EriksenThe SQL could look something like this.
SELECT dim_a.col_1, fact_a.measure_1
FROM db.dim_a
JOIN
db.fact_a
ON fact_a.col_2 = dim_a.col_2
WHERE fact_a.date = '28-nov-2012'
UNION ALL
SELECT dim_a.col_1, SUM (fact_b.measure_1)
FROM db.dim_a
JOIN
db.fact_b
ON fact_b.col_2 = dim_a.col_2
WHERE fact_b.date = '28-nov-2012'
UNION ALL
SELECT dim_a.col_1, SUM (fact_c.measure_1)
FROM db.dim_a
JOIN
db.fact_c
ON fact_c.col_2 = dim_a.col_2
WHERE fact_c.date = '28-nov-2012'
UNION ALL
SELECT NULL, SUM (fact_d.measure_1)
FROM db.fact_d
WHERE fact_d.date = '28-nov-2012'
I would appreciate if you could give me some hints for the RPD.
Thanks,
Henning -
How do you Select data from two tables with similar data amd merge the output together.
I have two Tables containing Sales Data. I want to read the Table a sort by date and accumulate dollars by order date. Then I want to read the second table and accumulate these dollar amounts by date and then merge the records together so that I gave 1 row
with amounts for type A and amounts for type b.
Here are the tables I am looking at.
Select Cast(J.Order_Date As Varchar(11))) As [Order Date]
,Sum(Case when Sales_Code like '%Comm%' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [Job Comm]
,Sum(Case when Sales_Code = '5-Day' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [Job Auto]
,Sum(Case when Sales_Code like '%Auto%" then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [Job Auto]
,Sum(Case when Sales_Code = '' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [Job Fixed]
,Sum(Case when Sales_Code = 'XX' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [SO Comm)
,Sum(Case when Sales_Code = 'YY' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [SO Auto)
,Sum(Case when Sales_Code = 'ZZ' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [SO Fixed)
from [PRODUCTION].dbo.Job As J
union all
Select Cast(SH.Order_Date As Varchar(11))) As [Order Date]
,Sum(Case when Sales_Code like '%Comm%' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [SO Comm]
,Sum(Case when Sales_Code = '5-Day' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [SO Auto]
,Sum(Case when Sales_Code like '%Auto%" then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [SO Auto]
,Sum(Case when Sales_Code = '' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [SO Fixed]
,Sum(Case when Sales_Code = 'XX' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [Job Comm)
,Sum(Case when Sales_Code = 'YY' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [Job Auto)
,Sum(Case when Sales_Code = 'ZZ' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [Job Fixed)
from [PRODUCTION].dbo.SO_Detail As SD
Inner Join [PRODUCTION].dbo.SO_Header As SH
on SD.Sales_Order = SH.Sales_Order
Group by J.Order_Date
Order by J.Order_Date Desc
Looking for output like
Order Date Job Comm Job AUto Job Fixed SO Comm SO AUto SO Fixed
Mar-11-2014 100.00 250.00 50.00 200.00 300.00 400.00
Mar-10-2014 500.00 340.00 0.00 110.00 400.00 500.00
Mar-09-2014 600.00 333.00 56.00 210.00 500.00 300.00
Thanks for your help
SWProductionSeeing the output it looks like what you need is this
select COALESCE(p.[Order Date],q.[Order Date]) AS [Order Date],
COALESCE([Job Comm],0) AS [Job Comm],
COALESCE([Job AUto],0) AS [Job AUto],COALESCE([Job Fixed],0) AS [Job Fixed],COALESCE([SO Comm],0) AS [SO Comm],COALESCE([SO AUto],0) AS [SO AUto],COALESCE([SO Fixed],0) AS [SO Fixed]
from
Select Cast(J.Order_Date As Varchar(11))) As [Order Date]
,Sum(Case when Sales_Code like '%Comm%' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [Job Comm]
,Sum(Case when Sales_Code = '5-Day' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [Job Auto]
,Sum(Case when Sales_Code like '%Auto%" then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [Job Auto]
,Sum(Case when Sales_Code = '' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [Job Fixed]
,Sum(Case when Sales_Code = 'XX' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [SO Comm)
,Sum(Case when Sales_Code = 'YY' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [SO Auto)
,Sum(Case when Sales_Code = 'ZZ' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [SO Fixed)
from [PRODUCTION].dbo.Job As J
)p
full join
Select Cast(SH.Order_Date As Varchar(11))) As [Order Date]
,Sum(Case when Sales_Code like '%Comm%' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [SO Comm]
,Sum(Case when Sales_Code = '5-Day' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [SO Auto]
,Sum(Case when Sales_Code like '%Auto%" then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [SO Auto]
,Sum(Case when Sales_Code = '' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [SO Fixed]
,Sum(Case when Sales_Code = 'XX' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [Job Comm)
,Sum(Case when Sales_Code = 'YY' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [Job Auto)
,Sum(Case when Sales_Code = 'ZZ' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [Job Fixed)
from [PRODUCTION].dbo.SO_Detail As SD
Inner Join [PRODUCTION].dbo.SO_Header As SH
on SD.Sales_Order = SH.Sales_Order
Group by J.Order_Date
)q
on p.[Order Date] = q.[Order Date]
Order by COALESCE(p.[Order Date],q.[Order Date]) Desc
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
Fact table with different dates
Hello,
In my fact table I have several date columns (order date, payment date, ....) and I have only one time table in my physical model.
For example this model
Fact table
order day
payment day
Timetable
day - pk
I want to create 2 fks in order to have time analyse with order date and payment date
FK1 : fact_table.order_day and timetable.day
FK2 : fact_table.payment_day and timetable.day
validating the model, OBI tells me that i cant' t have various joins between 2 tables
Anyone know how to solve this ? (I think it is a quite common problem)
Thanks in advanceCreate an alias for your dimension Timetable and then join that with your fact table. So basically you would have 2 dimensions, one joining with order day the other joining with payment day.
Thanks,
Venkat
http://oraclebizint.wordpress.com -
Error while accessing BSAD Table with dunning date
Hi ,
I developed a report for FI module accessing BSAD table with default customer ranges and for specific dunning dates - It ran for a very long time and timed out - (I know this is due to huge volume of data) -
Is there any way to access BSAD table easily with Dunning dates (Other than creating Index on it) ???
Or any standard function module available ??
Regards
Rajesh.Hi
Try the below tables for the dunning data details:
MHND Dunning Data
MHNDO Dunning data version before the next change
MHNK Dunning data (account entries)
MHNKA Version administration of dunning changes
MHNKO Dunning data (acct entries) version before the next chang
SKS -
How to check the number of rows in a table with input data?`
Dear all,
I am having a table ( with declaration of 5 rows during the init ) there's a next button which will add another 5 rows by pressing. Let say the user ony key in 7 rows of data.. how should i track it? coz these data act as input to my bapi function. One of the input field of my bapi is to state how many rows of data that a user had key in. Thank you.I think ur problem is empty records, u dont want to process empty table rows.
m I right?
if yes then just before processing the data / records, check for empty records and remove unwanted rows from the node.
for (int i = 0; i < TableNode.size(); i++)
if all cells of row(i) are empty
remove row(i) from Table Node.
OR if you dont want to remove empty rows from display (screen), then at the time of processing, transfer useful rows to a separate node and process that node.
Best Regards
Deepak -
Need to create a new row in table with same data as Primary key, but new PK
Hello Gurus ,
I have a table with one column as primary key, I need to create a new row in the table, but with same data as in one of the rows, but with different primary key, in short a duplicate row with diferent primary key ..
Any ideas of how it can be done without much complication?
Thanks in advance for your reply.
Reards,
Swapneel Kaleuser9970447 wrote:
Hello Gurus ,
I have a table with one column as primary key, I need to create a new row in the table, but with same data as in one of the rows, but with different primary key, in short a duplicate row with diferent primary key ..
Any ideas of how it can be done without much complication?
Thanks in advance for your reply.
Reards,
Swapneel Kalesomething like
insert into mytable values ('literal for new pk',
select non-pk-1,
non-pk-2,
non-pk-n
from mytable
where pk-col = 'literal for existing pk')
Maybe you are looking for
-
4g iPod touch not recognized by iTunes
I have a 4g iPod touch that is not recognized by iTunes, yet my old Shuffle still is. I went through the entire Apple assistant but no change in status.
-
HT1535 Downloaded audiobook to iPad but cannot move book to computer. Help? or iPhone
I downloaded an audiobook to my iPad, and though it is noted on my Account History, it is not in my audiobook inventory on iTunes. I set my iPad configuration to "manually" transfer content...didn't help. When I connect my iPad to my computer, the
-
JNI FindClass Error: Using the Invocation API from visual C++
I am using JNI invocation api in microsoft visual c++ to invoke java. When I use the FindClass method, I get a return value of 0. I have verified that the class "a" exists and believe have set the java class path appropriately. A valid jvm and jenv a
-
Hi, For ETL configuration i have installed and configured, 1. Oracle 10G DB 2. obiee and obia 7.9.6 3. informatica server (here i created repository and integration services) 4. DAC server 10g (setup for DAC is also configured like create warehouse t
-
Project Server 2013: Set-SPProjectPermissionMode error
Hi, In our environment, we need to use Project Server permission mode to fine tune permissions. According to documents, we need to run the Set-SPProjectPermissionMode command. However, when I ran it, I got the following error: Set-SPProjectPermission