Joining two tables with different DB
Hi
We have 2 sources DB2 and Oracle.
In DB2 we have two tables which stores.
Tbl1
Case_no Information1 Information2 Information3
11112 sddf asd null null
11113 asd asd null null
Tbl2
Inf Info1 Code Info3
Xedy Asdf 111 afder
Mad Tag 123 top
The above tables are complex join with this condition
Tbl1.case_no=Tbl1.case_no.
Oracle tbl
Code Code_desc
111 Very good
123 bad
My requirement is to join the tbl2 with Oracle tbl. Based on the codes in DB2 table I should display the Code_desc in my reports. Like this
Case_no Code Code_desc
11112 111 Very good
11113 123 bad
But I am getting the Cartesian result.
Case_no Code Code_desc
11112 111 Very good
11112 123 bad
11113 111 Very good
11113 123 bad
Please help to resolve.
Regards
MD
Select Oracletbl and tbl2, right click on them open physical diagram, selected objects. In the physical diagram page Create a join between Oracletbl and tbl2 with the condition code=code.
In business model create a complex join between these two. Now reload metadata/restart services check output.
Let me know if this does not work you.
Similar Messages
-
How do you join two tables from different Oracle schemas using a subquery
I am trying to join two tables from different Oracle schemas using a subquery. I can extract data from each of the tables without a problem. However, when I combine the select statements using a subquery I get the Oracle error *'ORA-00936: missing expression'*. Since each SELECT statement executes on its own without error I don't understand what is missing. The result set I am trying to get is to match up the LINE_ID from PDTABLE_12_1 in schema DD_12809 with the MAT_DESCRIPTION from table PDTABLE_201 in schema RA_12809.
The query is as follows:
sql = "SELECT [DD_12809].[PDTABLE_12_1].LINE_ID FROM [DD_12809].[PDTABLE_12_1] JOIN " _
+ "(SELECT [RA_12809].[PDTABLE_201].MAT_DESCRIPTION " _
+ "FROM [RA_12809].[PDTABLE_201]) AS FAB " _
+ "ON [DD_12809].[PDTABLE_12_1].PIPING_MATER_CLASS = FAB.PIPING_MATER_CLASS"
The format of the query is copied from a SQL programming manual.
I also tried executing the query using a straight JOIN on the two tables but got the same results. Any insight would be helpful. Thanks!
Edited by: user11338343 on Oct 19, 2009 6:55 AMI believe you are receiving the error because you are trying to JOIN on a column that doesn't exist. For example you are trying to join on FAB.PIPING_MATER_CLASS but that column does not exist in the subquery.
If you want to do a straight join without a subquery you could do the following
SELECT DD_12809.PDTABLE_12_1.LINE_ID
, FAB.MAT_DESCRIPTION
FROM DD_12809.PDTABLE_12_1
JOIN RA_12809.PDTABLE_201 AS FAB ON DD_12809.PDTABLE_12_1.PIPING_MATER_CLASS = FAB.PIPING_MATER_CLASS HTH! -
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 -
How to join two columns between two tables with different column names
Hi
How i can join 2 columns with different names between the 2 tables.
Can any one please give solution for this.
Thanks
ManuHi,
basic understanding of joins:
If you want to join 2 tables there should be matching column w.r.t. data and it's data type. You need not to have same column names in both the tables...
so, find those columns which has got same values.. -
Two tables with different filter values base on a analysis
Hi guys,
let assume that I have a analysis with columns : group_id and sales.
Based on it I would like to create two tables : table1 where group_id =1 and table2 where group_id = 2.
Is OBIEE capable of doing it?
Regards,
SlaviHi Slavi,
You can do that in single analysis, but you need to have the group_id column two times.
That is, bring group_id_1, group_id_2 (same column), sales
Now in table 1,
bring group_id_1, sales
Then in selection steps for group_id_1 -> Select Members -> Action choose keep only -> choose the filter value 1
This will filter the table 1 with group_id 1
In table2 bring group_id_2, sales
Then do the same step for group_id_2 with value 2.
now in same report you have two reports with different filter.
If you want you can keep the same column name for both group_id columns, I just kept group_id_1, group_id_2 for easy reference. -
Join two table in different instance
Hi,
I have two table in different instance .
IMEI in instance A
RCA_SMART_CARD in instance B
Below is the desc table :
SQL> desc RCA_SMART_CARD;
Name Null? Type
N_CARD_ID NOT NULL NUMBER(10)
C_CARD_SERIAL_NUMBER NOT NULL VARCHAR2(20)
C_SIM_MSISDN VARCHAR2(20)
C_SIM_IMSI VARCHAR2(20)
C_LINKED_CARD VARCHAR2(20)
N_PRO_IDENTIFIER NOT NULL NUMBER(4)
C_CARD_TYPE VARCHAR2(1)
N_SIM_STATE NUMBER(1)
N_EEPROM_SPACE_LEFT NUMBER(9)
N_VOLATILE_SPACE_LEFT NUMBER(9)
N_NONVOLATILE_SPACE_LEFT NUMBER(9)
N_CARD_OPTI NOT NULL NUMBER(15)
N_PRODUCT_ID NUMBER(10)
D_CREATION_DATE DATE
D_MODIFICATION_DATE DATE
D_STATUS_MODIFICATION_DATE DATE
SQL> desc IMEI;
Name Null? Type
MSISDN NOT NULL VARCHAR2(20)
IMEI NOT NULL VARCHAR2(16)
DATE_MOD NUMBER(13)
IMSI VARCHAR2(18)
ICCID VARCHAR2(20)
T_PROF RAW(20)
EXTRA_DATA VARCHAR2(100)
If I want to join two table together .
I want to search the number of record in IMEI that have N_SIM_STATE =1 in RCA_SMART_CARD .
The MSISDN in IMEI is equal to C_SIM_MSISDN in RCA_SMART_CARD .
How can I do and what is the sql statment ??
Please advice .First you need to decide, from where you want to execute the query.
Let us assume it is instance A(as per your example).
Then what you need to do is:
1. Create database link to instance B
*[url http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_5005.htm]Here* is the semantics.
2. After creating the database link to instance B, you can achieve the result set by running the below query:
SQL> select count(*) from IMEI t1 join RCA_SMART_CARD@<db_link_name> t2 on t1.MSISDN = t2.C_SIM_MSISDN where t2.N_SIM_STATE = 1
Hope it helps!
Cheers,
AA -
Want to Join two tables with cursors
Can anyone tell me how to join two tables only by cursors.
Not with:
1.Joining condition
2.Procedure etc.
Only cursors with passing parameters.
SowmyaThis is my assignment. I want to get the matching records from both tables. I have pk, fk for both tables for deptno.Can I pass parameter for this.
dept table:
deptno deptname
10 sales
20 Erp
30 hr
40 marketing
emp table:
Empno deptno Name
1 10 lee
2 20 hans
3 10 peter
4 30 james
5 30 king
Output should be:
deptno empname empno deptname
10 lee 1 sales
10 peter 3 erp
30 james 4 hr
30 king 5 marketing -
Join two tables with no matching records
Hi All,
I have two tables which have got data as below. Now I need to join those two tables but there are no matching rows or columns in those tables. I have used OUTER JOIN but query was taking more than 5 mnts to run. Whats the best way to join two tables where
there are no matching records.
Table : Sections &Table : orders
I am expecting the final output like I have mentioned below.
How can i write a JOIN. Note there are no matching records from both the tables.
Pls.This is a very urgent requirement.Regards
-pepThanks Elrand. I have one question. What if I want to add 10 more parameters in @Section table then
the logic I have written below will not work. I will have to make it dynamic. Any suggestions.?
declare @test table (RowNo INT,CokeType NVARCHAR(MAX),BeginUsage dateTIME)
declare @Section table (SectionName NVARCHAR(100))
insert into @Section values ('CokeType')
insert into @Section values ('BeginUsage')
insert into @test values (1,'OMV - 02E (04/2012)','01-02-2014')
insert into @test values (2,'OMV - 02E (04/2012)','01-03-2014')
insert into @test values (3,'PCIC - 01 (01E/2013)','01-04-2014')
insert into @test values (4,'PCIC - 01 (01E/2013)','01-05-2014')
insert into @test values (5,'PCIC - 01 (E) - 07/2011 & Alba /2010 (C/F) 05/2011','01-06-2014')
select * from @Section
select * from @test
SELECT
RowNo,SectionName,
CASE
WHEN(SectionName = 'CokeType') THEN CokeType
ELSE
CAST (BeginUsage AS VARCHAR(MAX))
END
AS DATA
FROM @Section AS S
CROSS APPLY
(SELECT T.RowNo,T.CokeType,T.BeginUsage FROM @test T) P
ORDER BY SectionName DESC -
Joining Two Tables with a DISTINCT column value
I have two tables I need to join, but the 'left' table I only need DISTINCT for a column.
create table t1
bid number(8),
b_number number(8),
dset varchar2(20),
misc varchar2(20)
create table t2
cid number(8),
track number(8)
select bid, cid
from ( select bid, b_number
from t1
where dset = 'ABC1234'
and misc = 'TEXT'
) x,
( select cid, track
from t2
where exists ( select 1 from t2 where t2.track = t1.b_number )
) z
where x.b_number = z.trackI only need records with DISTINCT cid values, but I keep getting multiple instanced of cid.
Any suggestions?
Thanks!Maybe this?
select distinct cid
from t2
where track in
select b_number
from t1
where dset = 'ABC1234'
and misc = 'TEXT'
) -
How to join two tables with no similar columns
Hi all,
I have two tables as follows:
Table T1 have Attributes as follows:
GLCODE,
BRANCH,
ITEM_NUMBER,
DEMAND_DATE,
QUANTITY,
SOURCE
Table T2 have Attributes as follows:
FORECAST_DATE
Now in SQL if run the following stattement iam getting out put.
SELECT GLCODE,BRANCH,ITEM_NUMBER,DEMAND_DATE,QUANTITY, SOURCE,(SELECT DISTINCT FORECAST_DATE FROM T2) FROM T1
The above SQL Statement giving correct results for me.
The same SQL Statement how can we implement in mapping level?
Regards,
AvaJaap van,
>
You have to specify an outer join, but how do you do that if there is no join to begin with? I would do the following (which I didn't test yet):
add an extra column (say C_JOIN) to the T2-ingroup of the join operator and fill it with from a constant operator with say value 1. Then use T2.C_JOIN (+) = 1 as the join condition.
If every record in T2 is guaranteed to have the same value, instead of using a deduplicator, which will read all records, sort them and deduplicate them, you can use a filter with filter condition ROWNUM < 2, which only will read one record.
I am facing almost the same problem but not entirely thou and I was wondering if you have an idea how to even start.
Problem:
I got this table:SQL> desc ita.tpis32_job_status
Name Null? Type
JOBID NOT NULL NUMBER
T1_ID NUMBER
QID NUMBER
REQ_TYPE VARCHAR2(10)
SUBMIT_TIME DATE
OWNERID VARCHAR2(30)
DESCRIPTION VARCHAR2(150)
STARTTIME DATE
ENDTIME DATE
STATUS VARCHAR2(50)
ERROR_ID NUMBER
TABLE_NAME VARCHAR2(30)
SERVER_ID VARCHAR2(10)
DATABASE VARCHAR2(20)
PRIORITY NUMBER
NUM_LINES NUMBER
PROCESS_ID NUMBER
QUE_TIME NUMBER
STATUS_CODE NUMBER
ERROR_MSG VARCHAR2(500)
NUM_LINES_TS NUMBER
REMOTE_STATUS NUMBER
This the above table, i am looking for JOBID (a five digit number) like 25875.
What I want to do is add or append this five digit number to a string to find the corresponding table in dba_tables or all_tables. The only way I have try to do this is by writing PLSQL as you see from here:
Re: Use PLSQL to delete tables dynamically
When the select is writing properly, the result of the five digit number from JOBID and the string should look like the below result (job_(five digit_%).
My problem is there is no relationship between ALL_TABLES and the my own table (ita.tpis32_job_status). Any help will be appreciated.
TABLE_NAME
JOB_58871_OUTDATA
JOB_58868_TS
JOB_58868_OUTDATA
JOB_58867_TS
JOB_58867_CMDLBL_2
JOB_58867_OUTDATA
JOB_58866_TS -
Outer join two tables with query search record attached to both tables
When I create a query with two tables that have query search records attached with outer join, PS seems to do a natural join (cartesian). We are on PT8.48.
Is there a workaround for this issue. I do not want to remove query search record on either of the tables.
I am trying to create an Emergency contact report. I am using two tables PS_EMPLOYEES and PS_EMERGENCY_CNTCT. Here is the sql PeopleSoft query generated when I did Left outer Join.
Query SQL:
SELECT A.EMPLID, A.NAME, A.ADDRESS1, A.CITY, B.PRIMARY_CONTACT, B.ADDRESS1, B.CITY, B.STATE, B.POSTAL, B.RELATIONSHIP, A.DEPTID, A.JOBCODE, A.COMPANY, A.EMPL_TYPE
FROM (PS_EMPLOYEES A LEFT OUTER JOIN PS_EMERGENCY_CNTCT B ON A.EMPLID = B.EMPLID ), PS_EMPLMT_SRCH_QRY A1, PS_PERS_SRCH_QRY B1
WHERE A.EMPLID = A1.EMPLID
AND A.EMPL_RCD = A1.EMPL_RCD
AND A1.OPRID = 'SREESR'
AND (B.EMPLID = B1.EMPLID OR B.EMPLID IS NULL )
AND B1.OPRID = 'PS'
Appreciate any help.I think there are fixes for this issue in later tools releases (Report ID 1544345000). I'm not sure about 8.48, but you might try the workaround documented in
E-QR: Left Outer Joins with Security Records are returning unexpected results [ID 651252.1]
on Oracle Support.
Regards,
Bob -
Joining Two Tables with Total Amount
Hi All,
I'm trying to join to tables P02 and P30 on the invoice no fields but getting duplicates. In table P30 we need to sum the payment column per invoice to get the actual payment amount. This then needs to Join to table P02. I have uploaded sample
data on this link and provided an example on how the output should like.
https://app.box.com/s/pu8oa4f3jhrhm0ylshdz2fuo7541vn4z
Thanks
JagI figured out why the duplicates appear. I'm attaching another table supplier to fill in the missing propcode when running the query below
SELECT P02.P02_UNIQUE, p30.PROP_CODE, P02.SUPP_ALPHA+P02.SUPP_NUMERIC As SupplierCode, P02.INV_ALPHA+P02.INV_NUMERIC AS InvoiceNo,TotalPayment, Year, Month
FROM P02
CROSS APPLY (
SELECT PROP_CODE, SUM(TOTAL_AMOUNT) AS TotalPayment, P30.INVOICE_NUMB, DATEPART(year,[CREATED_DATE_SQL]) AS [Year], DATEName(Month,[CREATED_DATE_SQL]) AS [Month]
FROM dbo.P30
WHERE P02.INV_ALPHA+P02.INV_NUMERIC = P30.INVOICE_NUMB
GROUP BY PROP_CODE, COST_CENTRE, DATEPART(year,[CREATED_DATE_SQL]), DATEName(Month,[CREATED_DATE_SQL]), P30.INVOICE_NUMB
)P30
Where P02.SUPP_ALPHA+P02.SUPP_NUMERIC = '668'
Result below and the last row the prop_code is missing
I have another table supplier which has the suppliercode and propcode so was trying to use the prop_code field from supplier table instead of P30 table to fill in the gap. But when i do that i get duplicates and wrong values.
I have updated the sample data with supplier table. -
Join two tables with an aggrefate funtion in it
say I have two tables defined as
t1(id1 number primary key, val1 varchar2(10));
t2(id1 number, id2 number, val2 varchar2(10),
constraint primary key(id1, id2),
constraint foreign key id1 references t1(id1));
The values in T1 are
id1, val1
1, abc
2, def
3, xyz
The values in T2 are
id1, id2, val2
1, 1, pqr
1, 2, mno
2, 1, efg
3, 1, def
3, 2, fgh
3, 3, hij
i.e for each id1 in t1 there could be mulltiple values in T2.
i need to get the val2 from t2 for each id1 in t1 where id2 is maximum
The results should be
1, 2, mno
2, 1, efg
3, 3, hij
I can open a cursor for the records in t1 and can query for each row in T2 where id2 is maximum.
but, how do I do this one join query.
i did soem thing like
select t1.id1, t2.id2, t2.val2
from t1, t2
where t1.id1 = t2.id1
and exists (select 1 from t2 X where t2.id1 = t1.id1 and X.id2 = max(t2.id2)
but it did not work!select t1.id1, t2.id2, t2.val2
from t1, t2,
(select id1, max(id2) id2
from t2
group by id1) t3
where t1.id1 = t2.id1
and t2.id1 = t3.id1
and t2.id2 = t3.id2
[\code]
In this case you don't really need to reference t1 at all, but I'm assuming that this is a simplified version of what you need, and are pulling other values of t1 too. -
Joining two tables on different datatype key
Hi,
I have two two tables,
create table table1( primkey1 double, name varchar(30))
create table table2( primkey2 double, name varchar(30))
Now I have to join these two table in RPD. I tried to join but i got an error.
plz tell me the way to join these two tables.
thank you,Could you please provide the error message?
-
Comparing Data between two tables with different structure
Hi,
I have 2 tables T1 and T2. Both tables have different structure. I have to check for rows missing in T1 which exist in T2 and vice-versa. I can do that using MINUS operator. But the part where the data exists in both T1 and T2, I have to compare some columns (9 columns the names of this column coming from a meta-data table) if they have same values. If not an exception has to be generated.
Any help is appreciated.
ThanksHi,
Whenever you need help on this forum, post:
(1) The version of Oracle (and any other relevant software) you're using
(2) A little sample data (just enough to show what the problem is) from all the relevant tables
(3) The results you want from that data (4) Your best attempt so far
Executable SQL statements (like "CREATE TABLE AS ..." or "INSERT ..." statements) are best for (2).
Formatted tabular output is okay for (3). Type before and after the tabular text, to preserve spacing.
What do you mean by "an exception has to be generated"?
Do you want to raise an error?
Do you want something to appear in the result set?
MINUS finds rows that are in one result set, but not in another.
INTERSECT finds rows that are in both result sets.
Column names have to be hard-coded into the SQL statement. If you want to write something now that will get column names from a metadata table sometime in the future, then you have to use dynamic SQL. SQL*Plus sometimes has quick and dirty ways of doing dynamic SQL, so say whether you're using SQL*Plus or not.
Maybe you are looking for
-
How can I use a variable as an array's name?
Ok I have several arrays in my code (lets call them "array1", "array2" etc) and I want to load them based on the users input. So if the user enters array1, I want the first array to be loaded, and the same with the other arrays. I tried saving the us
-
I want to locate a button on a web page and click it. That's it. Sounds easy but I don't how to locate the button. I can't link to the web page because you need to be a member to view it. I also want to learn from this so I can locate a button on a d
-
Openbox-svn6175 wired problem [solved]
I have a wired problem with the new openbox-svn revision. I use pypanel and e.g i open urxvt and firefox, and will switch from firefox to urxvt I can't get urxvt in the foreground, only when I start first firefox , then urxvt, switch to firefox and t
-
MobileMe account split from AppleID during iCloud transition
I previously had an AppleID account under a non-Apple email address. Let's call it [email protected] I use this account for my iTunes transactions, Mac support, etc. It also paid for me MobileMe account, which we'll [email protected] When I upgraded
-
IPhone 2G Shuts Down upon Start-up- Advanced User
My phone boots up with the Apple Icon. Just before the home screen appears, I get the while scroll and it shutsdown. I restored the phone on ITunes. Saw the homescreen once when it said it was now activated and ready to go. The battery died, so I cha