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
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! -
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
MDSelect 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. -
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?
-
Joining two tables in two different schema
Hi All,
I have a requirement to join two tables in two different schema. How to join these two tables in view object.
Many thanks in advance.
Regards
Kaushik Gopalakrishnan1) If these tables are in one and same database instance, then you can join them by specifying the fully-qualified table names (inlcuding the schema name), for example:
SELECT ...
FROM schema_A.table1 T1, schema_B.table2 T2
WHERE T2.parent_code = T1.code
AND ...2) If the tables are in different database instances, then you can create a database link in one of the databases and access the table from the other database via the DB link, for example:
SELECT ...
FROM schema_A.table1 T1, schema_B.table2@mydblink T2
WHERE T2.parent_code = T1.code
AND ...3) If the tables are in different database instances and there is no option for DB links, then you cannot join the tables in an ADF ViewObject.
Dimitar -
I am trying to develop a query in MS Access 2010 to join two tables using three joins, one of which is a (between) date range. The tables are contained in Access. The reason
the tables are contained in access because they are imported from different ODBC warehouses and the data is formatted for uniformity. I believe this cannot be developed using MS Visual Query Designer. I think writing a query in SQL would be suiting this project.
ABCPART links to XYZPART. ABCSERIAL links to XYZSERIAL. ABCDATE links to (between) XYZDATE1 and ZYZDATE2.
[ABCTABLE]
ABCORDER
ABCPART
ABCSERIAL
ABCDATE
[ZYXTABLE]
XYZORDER
XYZPART
XYZSERIAL
XYZDATE1
XYZDATE2Thank you for the looking at the post. The actual table names are rather ambiguous. I renamed them so it would make more sense. I will explain more and give the actual names. What I do not have is the actual data in the table. That is something I don't have
on this computer. There are no "Null" fields in either of the tables.
This table has many orders (MSORDER) that need to match one order (GLORDER) in GLORDR. This is based on MSPART joined to GLPART, MSSERIAL joined to GLSERIAL, and MSOPNDATE joined if it falls between GLSTARTDATE and GLENDDATE.
[MSORDR]
MSORDER
MSPART
MSSERIAL
MSOPNDATE
11111111
4444444
55555
2/4/2015
22222222
6666666
11111
1/6/2015
33333333
6666666
11111
3/5/2015
This table has one order for every part number and every serial number.
[GLORDR]
GLORDER
GLPART
GLSERIAL
GLSTARTDATE
GLENDDATE
ABC11111
444444
55555
1/2/2015
4/4/2015
ABC22222
666666
11111
1/5/2015
4/10/2015
AAA11111
555555
22222
3/2/2015
4/10/2015
Post Query table
GLORDER
MSORDER
GLSTARTDATE
GLENDDATE
MSOPNDATE
ABC11111
11111111
1/2/2015
4/4/2015
2/4/2015
ABC22222
22222222
1/5/2015
4/10/2015
1/6/2015
ABC22222
33333333
1/5/2015
4/10/2015
3/5/2015
This is the SQL minus the between date join.
SELECT GLORDR.GLORDER, MSORDR.MSORDER, GLORDR.GLSTARTDATE, GLORDR.GLENDDATE, MSORDR.MSOPNDATE
FROM GLORDR INNER JOIN MSORDR ON (GLORDR.GLSERIAL = MSORDR.MSSERIAL) AND (GLORDR.GLPART = MSORDR.MSPART); -
Hi,
I have a query that joins two tables in the same database, the result needs to be loaded in a destination DB table. How do I do this in SSIS package?
thank you !
Thank You Warmest Fanny PiedPlease take a look at these links related to your query.
http://stackoverflow.com/questions/5145637/querying-data-by-joining-two-tables-in-two-database-on-different-servers
http://stackoverflow.com/questions/7037228/joining-two-tables-together-in-one-database -
Package Error! join to tables in different schemas
Hi
I get an error whwn I want to put my query into package
I have two tables in different schemas and I joined them and it works when I compile it
but in the SP it doesn't works
Is anbody help me? please
Table1 in Schema1
Table2 in Schema2
TableID is the column which I join two tables (Table1.TableID=Table2.TableID)
User1 has Select grant to both tables (it works when I run the query but in the sp which is in the package it doesn't work)
Package1 in Schema1query is working
but when I put that query in to package, Package is giving error like "table or view does not exist"
Table1 in Schema1
Table2 in Schema2
TableID is the column which I join two tables (Table1.TableID=Table2.TableID)
User1 has Select grant to both tables (it works when I run the query but in the sp which is in the package it doesn't work)
Package1 in Schema1
Select * from Schema1.Table1
Inner join Schema2.Table2 on Table1.TableID=Table2.TableID
is working in editor but
CREATE OR REPLACE PACKAGE Schema1.PCKG_packagename AS
PROCEDURE SP_procedurename
Select * from Schema1.Table1
Inner join Schema2.Table2 on Table1.TableID=Table2.TableID;
END SP_procedurename;
END PCKG_packagename ;
is not working
Must I give grant to Package?
Edited by: 874779 on 25.Tem.2011 03:37
Edited by: 874779 on 25.Tem.2011 03:51 -
How to prevent Oracle from using an index when joining two tables ...
How to prevent Oracle from using an index when joining two tables to get an inline view which is used in an update statement?
O.K. I think I have to explain what I mean:
When joining two tables which have many entries sometimes it es better not to use an index on the column used as join criteria.
I have two tables: table A and table B.
Table A has 4.000.000 entries and table B has 700.000 entries.
I have a join of both tables with a numeric column as join criteria.
There is an index on this column in table A.
So I instead of
where (A.col = B.col)I want to use
where (A.col+0 = B.col)in order to prevent Oracle from using the index.
When I use the join in a select statement it works.
But when I use the join as inline view in an update statement I get the error ORA-01779.
When I remove the "+0" the update statement works. (The column col is unique in table B).
Any ideas why this happens?
Thank you very much in advance for any help.
Regards HartmutI think you should post an properly formatted explain plan output using DBMS_XPLAN.DISPLAY including the "Predicate Information" section below the plan to provide more details regarding your query resp. update statement. Please use the \[code\] and \[code\] tags to enhance readability of the output provided:
In SQL*Plus:
SET LINESIZE 130
EXPLAIN PLAN FOR <your statement>;
SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY);Usually if you're using the CBO (cost based optimizer) and have reasonable statistics gathered on the database objects used the optimizer should be able to determine if it is better to use the existing index or not.
Things look different if you don't have statistics, you have outdated/wrong statistics or deliberately still use the RBO (rule based optimizer). In this case you would have to use other means to prevent the index usage, the most obvious would be the already mentioned NO_INDEX or FULL hint.
But I strongly recommend to check in first place why the optimizer apparently seems to choose an inappropriate index access path.
Regards,
Randolf
Oracle related stuff:
http://oracle-randolf.blogspot.com/
SQLTools++ for Oracle:
http://www.sqltools-plusplus.org:7676/
http://sourceforge.net/projects/sqlt-pp/ -
Hi
I am beginner in Oracle. I want some help in joining two tables and adding a new attribute to the resulting table
For xample:
Table Name: Texas*
Ename Enumber Sal
John 1 10
Akl 2 20
Renka 3 25
Table Name: California_
Ename Enumber Sal
Rada 4 15
Paul 5 16
Mikler 6 12
Now I want to join these Tables Texas and California and I want to Add Another attribute to the resulting table State
Table Name: Emplyee_
Ename Enumber Sal State
John 1 10 Texas
Akl 2 20 Texas
Renka 3 25 Texas
Rada 4 15 California
Paul 5 16 California
Mikler 6 12 California
Thanks in advance
Santosh
Edited by: user10904473 on Mar 29, 2009 2:45 PMAre you sure you want to join the tables? It seems like you want to UNION them
SELECT ename, enumber, sal, 'Texas' state
FROM texas
UNION ALL
SELECT ename, enumber, sal, 'California' state
FROM californiaOf course, having different tables for different states is a very poor way to model employee data, so I'd strongly suggest fixing that problem if these are real tables rather than a school assignment.
Justin -
Records from two tables in different DB's
I have two tables (in different DB's) that I need to build
results from. I want to return results from all records in table A
and when a matching record in table B is found, retrieve the value
of a sqlbit field. The catch is that there may or may not be any
records in Table B that match Table A, and there may be more than
one record in Table B, but always only one record for Table A.
Table A is [Order] (yes I know, a reserved word - not my
design) and Table B is tblOrderFollowup - here is my current SQL
statement:
****************BEGIN SQL*************************
SELECT o.StoreID AS xStore
, o.Time AS dCreated
, o.ID AS xPurchase
, c.FirstName AS sFirstName
, c.LastName AS sLastName
, c.Company AS sCompany
, c.ID AS xCustomer
, o.Type AS xType
, o.Closed AS bClosed
, o.Tax AS nTax
, fu.OrderID AS xFUOrder
, fu.bComplete AS xFUComplete
FROM [Order] o
INNER JOIN Customer c
ON o.CustomerID = c.ID
AND o.StoreID = c.StoreID
LEFT OUTER JOIN db2.dbo.tblOrderFollowup fu
ON o.ID = fu.OrderID
AND o.StoreID = fu.StoreID
WHERE o.StoreID IN ( #allowableStoreIDs# )
AND o.StoreID = <cfqueryparam cfsqltype="cf_sql_integer"
value="#FORM.StoreID#" />
AND o.Time >= <cfqueryparam
cfsqltype="cf_sql_timestamp"
value="#CreateODBCDateTime(StartOfDay(FORM.dFrom))#" />
AND o.Time <= <cfqueryparam
cfsqltype="cf_sql_timestamp"
value="#CreateODBCDateTime(EndOfDay(FORM.dTo))#" />
AND o.Closed = <cfqueryparam cfsqltype="cf_sql_bit"
value="1" />
ORDER BY o.Time DESC
***********END SQL**********************
The problem here is that when I have more than 1 record per
OrderID/StoreID pair in Table B, I get more than one result - I
only want one. I am guessing I need a sub query, but don't know how
to go about doing that at all ...You say you want only one result. Do you know which one you
want?
By the way, your query is probably not giving you the right
answer. My experience is that if you do this:
select stuff
from table1 left join table2 on something
where table2.somefield = somevalue
you get the wrong answer. What I do instead is,
select stuff
from table1 left join
(select stuff from table2
where whatever) need_an_alias on somthing -
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 -
Error joining two tables in graph pane
While trying to join two tables by draging one column onto a column of another table in a graph pane, an error dialog with the following message appears:
"Drag and drop failed. Please drag a column from one table in the graph onto a column of another table in the graph pane. If you are trying to create a self join, please create another instance of the table and adding same table to the graph pane."
How do join two tables in the query editor graphically?I also have the same problem. I use MySQL. I do not have any foreign keys in my tables. If I try to create table joins graphically myself I get the following error:
"Drag and drop failed. Please drag a column from one table in the graph onto a column of another table in the graph pane. If you are trying to create a self join, please create another instance of the table and adding same table to the graph pane."
When I type SQL query(similar to the following) in the in the query editor it dosent work: (As a result same row is appearing more than one time when I test the application)
WHERE login.USERNAME=me.NAME
In the above Mayagiri suggested a turorial using Pointbase and tables with foreign keys which is not directly connected with problem.(Beacuse it seems no problems in Pointbase tables with foreign keys)
Any further is very much appreciated. Thanks in advance. -
Using a view to join two tables
Thank you in advance for any advice you can lend.
I am using this code in my MySQL db to create a view.
select
job.id as job_id,
umr_cost_calculation.plant_name,
max(umr_cost_calculation.id) as max_id
from
job,
umr_cost_calculation
where
job.id = umr_cost_calculation.job_id
group by job.id , umr_cost_calculation.plant_name
I did this so I can join two tables and pull in the most current cost data for a specific plant. The report will, at times, show the wrong (older) data. I can re-run the report, filter to just the one job and see again the wrong data. When I add the max_id to the report, it display the id and updates the report with the correct data. It appears that the view was stale and by adding the ID to the report this fixed the issue.
1) Is this the best way to make this join? I don't see how Crystal supports a subquery to make a join (this is why I used the view).
2) If I leave the max_id on the report, will this force the view to always update?Try:
Select
D1.EmpLoginID,
Count(D1.ID),
Count(D1.AlarmCode),
D1.EmpName,
D1.EmpAddress,
D2.Db2Count
FROM DB1.Data D1
LEFT JOIN (SELECT
empLoginID, Count(*) as Db2Count
FROM DB2.ALL_Database
WHERE site = 'Atlanta'
GROUP BY empLoginID
) D2
ON D1.EmpLoginID = D2.EmpLoginID
GROUP BY D1.empLoginID, D1.EmpName, D2.EmpAddress, D2.Db2Count
Order BY D1.empLoginID ASC
For every expert, there is an equal and opposite expert. - Becker's Law
My blog
My TechNet articles -
No Easy Way to Join on Tables from Different Schemas
Hi,
The company policy does not allow to join on tables from different schemas or use db links...
I'm tasked to come up with a Perl script that does exactly that - allows for the SELECT statement to do several joins on 3 different schemas. In addition 1 of the schemas is on the different host altogether.
Upping the privileges for my user and allowing db links is not an option...Can someone, please help me to understand on a conceptual level how would I use Perl and what logic would it have and what would it (perl) do?
Thank you,Court in the wrong job... ;)
It's like a librarian who is a hard rock artist maintaining the silence in the premises. ;)
My dear friend, i don't think this is the right place for your requirement. This is the PL/SQL forum. If you have any problem related PL/SQL or SQL you can place that here.
Regards.
Satyaki De.
Maybe you are looking for
-
Hyperlinks in .chm not working
I am authoring my content in Frame 7.2, and importing the Frame chapter files one at a time into RH7. The Frame files have numerous cross-references - some to headings in the same chapter, some to headings in other chapters. When I import the chapter
-
Hi All, Where can I go to set tolerance for vendor check payments? Eg: If I am paying a vendor a check for $1, I want the system to put a tolerance around that and prevent me from paying a check worth that small an amount. Thanks, Deki
-
TS20000139 Enter and Send message
Hi We are using Trip request workflow WS20000040. and when the approver rejects the trip request then the task TS20000139 executes and pops up a window where approver writes his comments , receiver id (employee) and will send it to the employee. The
-
I Purchased element 11 in 2012 and would like to install it on new laptop
-
ODBC 8.1.6.1
I received the following error in the process of attaching an Access 2000 database. Internal error message: 3151ODBC - connection failed!