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
Manu
Hi,
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..
Similar Messages
-
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 -
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. -
hi
how to join two tables using inner join if the first table has two primary keys and second table has 3 primary keysWould describe type of joins in ABAP, which might differ with other joins.
The join syntax represents a recursively nestable join expression. A join expression consists of a left-hand and a right- hand side, which are joined either by means of INNER JOIN or LEFT OUTER JOIN. Depending on the type of join, a join expression can be either an inner (INNER) or an outer (LEFT OUTER) join. Every join expression can be enclosed in round brackets. If a join expression is used, the SELECT command circumvents SAP buffering.
On the left-hand side, either a single database table, a view dbtab_left, or a join expression join can be specified. On the right-hand side, a single database table or a view dbtab_right as well as join conditions join_cond can be specified after ON. In this way, a maximum of 24 join expressions that join 25 database tables or views with each other can be specified after FROM.
AS can be used to specify an alternative table name tabalias for each of the specified database table names or for every view. A database table or a view can occur multiple times within a join expression and, in this case, have various alternative names.
The syntax of the join conditions join_cond is the same as that of the sql_cond conditions after the addition WHERE, with the following differences:
At least one comparison must be specified after ON.
Individual comparisons may be joined using AND only.
All comparisons must contain a column in the database table or the view dbtab_right on the right-hand side as an operand.
The following additions not be used: NOT, LIKE, IN.
No sub-queries may be used.
For outer joins, only equality comparisons (=, EQ) are possible.
If an outer join occurs after FROM, the join condition of every join expression must contain at least one comparison between columns on the left-hand and the right-hand side.
In outer joins, all comparisons that contain columns as operands in the database table or the view dbtab_right on the right-hand side must be specified in the corresponding join condition. In the WHERE condition of the same SELECT command, these columns are not allowed as operands.
Resulting set for inner join
The inner join joins the columns of every selected line on the left- hand side with the columns of all lines on the right-hand side that jointly fulfil the join_cond condition. A line in the resulting set is created for every such line on the right-hand side. The content of the column on the left-hand side may be duplicated in this case. If none of the lines on the right-hand side fulfils the join_cond condition, no line is created in the resulting set.
Resulting set for outer join
The outer join basically creates the same resulting set as the inner join, with the difference that at least one line is created in the resulting set for every selected line on the left-hand side, even if no line on the right-hand side fulfils the join_cond condition. The columns on the right-hand side that do not fulfil the join_cond condition are filled with null values.
Note
If the same column name occurs in several database tables in a join expression, they have to be identified in all remaining additions of the SELECT statement by using the column selector ~.
Example
Join the columns carrname, connid, fldate of the database tables scarr, spfli and sflight by means of two inner joins. A list is created of the flights from p_cityfr to p_cityto. Alternative names are used for every table.
PARAMETERS: p_cityfr TYPE spfli-cityfrom,
p_cityto TYPE spfli-cityto.
DATA: BEGIN OF wa,
fldate TYPE sflight-fldate,
carrname TYPE scarr-carrname,
connid TYPE spfli-connid,
END OF wa.
DATA itab LIKE SORTED TABLE OF wa
WITH UNIQUE KEY fldate carrname connid.
SELECT ccarrname pconnid f~fldate
INTO CORRESPONDING FIELDS OF TABLE itab
FROM ( ( scarr AS c
INNER JOIN spfli AS p ON pcarrid = ccarrid
AND p~cityfrom = p_cityfr
AND p~cityto = p_cityto )
INNER JOIN sflight AS f ON fcarrid = pcarrid
AND fconnid = pconnid ).
LOOP AT itab INTO wa.
WRITE: / wa-fldate, wa-carrname, wa-connid.
ENDLOOP.
Example
Join the columns carrid, carrname and connid of the database tables scarr and spfli using an outer join. The column connid is set to the null value for all flights that do not fly from p_cityfr. This null value is then converted to the appropriate initial value when it is transferred to the assigned data object. The LOOP returns all airlines that do not fly from p_cityfr.
PARAMETERS p_cityfr TYPE spfli-cityfrom.
DATA: BEGIN OF wa,
carrid TYPE scarr-carrid,
carrname TYPE scarr-carrname,
connid TYPE spfli-connid,
END OF wa,
itab LIKE SORTED TABLE OF wa
WITH NON-UNIQUE KEY carrid.
SELECT scarrid scarrname p~connid
INTO CORRESPONDING FIELDS OF TABLE itab
FROM scarr AS s
LEFT OUTER JOIN spfli AS p ON scarrid = pcarrid
AND p~cityfrom = p_cityfr.
LOOP AT itab INTO wa.
IF wa-connid = '0000'.
WRITE: / wa-carrid, wa-carrname.
ENDIF.
ENDLOOP. -
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 -
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 -
How to update two tables with trigger
Hi:
how to update two tables with trigger ?
I have two tables :
(1)ASIA
MI number;
(2)ASIA_P
ID number;
When I insert a new value into the asia.MI ,I also can
insert the same value into the asia_p.id field.
I have write a trigger as follows but it does't work.
create or replace trigger MI_TRG
before insert on asia
for each row
declare
seq number;
begin
select MI_SEQ.Nextval into seq from dual;
:new.MI:=seq;
insert into ASIA_PRO(MI_ID)
values
(seq);
end MI_TRG;
How to realize it ?
thanks
zzmWhy do you say it does not work?
-
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 -
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 -
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. -
How to put two files with the same name into the same folder?
How can I put two files with the same name and the same extention into the same directory?
Is this even possible?
Thanks in advance.Are you sure? I would be very surprised if that was the case.
How does the computer/filing system differentiate the files, if not by their names?
How do you tell the computer which one you want? (On the command line.) -
How to combine two applications with different workspaces in APEX
Hi,
Can anyone help out in merging two applications with different workspaces in APEX 3.2 ?
Thanks in advance,Hello Satya,
>> I am Satya …
Please take one more step to help us and update your forum handle to something friendlier than user123… Thanks.
>> Can anyone help out in merging two applications with different workspaces in APEX 3.2 ?
This is not a trivial task.
You didn’t mentioned if both workspaces sharing the same APEX instance, or they are on two different instances (machines). I believe the latter is a pre-condition to a success.
First you need to remember that importing an APEX component, like a single page, is possible only to the same application that it was exported from. This is still valid if you have the same workspace on two separate APEX instances – one is an import of the other (which makes it an identical copy). Still, the application ID must be the same, or you’ll get the following error: “This page was exported from a different application or from an application in different workspace. Page cannot be installed in this application.”
You can’t simply manipulating the export file, if the two workspaces are sharing the same APEX instance, as all workspaces on the same instance shares the same APEX metadata files, and you’ll receive a “unique constraint violated” error messages. That means you can’t import one application into the workspace of the other, even if you are using a different application ID.
As far as I can see, the only viable way of doing an application merge is to have two identical workspaces, on two separate APEX instances. The two applications should share the same application ID, although this parameter can be changed in the import file. You should export the page in one application – on the first instance – and import it into the other application – on the second instance.
You should also make sure that the exported page ID doesn’t exist on the target application, otherwise it will be replaced by the new imported page. Also, if the imported page include references to shared components that are not defined on the second application, it might also pose a problem.
As I said, this is not trivial. The benefits are mostly depend on the amount and complexity of the pages you want to merge. If they are not many, and simple, you should consider just re-creating them on the target application. If they are very complex, the merge might fail anyway.
Regards,
Arie.
Please remember to mark appropriate posts as correct/helpful. For the long run, it will benefit us all. -
Create n tables with different number names
Hi guys, I work with SQL Server 2008 and OS Windows Server 2008 R2 64 bits. I have to create 10 tables with different names e.g. 'Image1', 'Image2', and so on. For this goal, I use a loop and concatenation. Here is the code:
DECLARE @i INT
DECLARE @v_table_n CHAR
SET @i=1
SET @v_table_n='Image'
WHILE (@i<=10)
BEGIN
DECLARE @STR VARCHAR(100)
SET @STR = 'CREATE TABLE SQL_DB_Filestream.dbo.Image1' + @v_table_n + CAST(@i AS VARCHAR(10)) + ' (
[ID_RowFeatVec] INTEGER NOT NULL PRIMARY KEY,
[CF1] FLOAT,
[CF2] FLOAT,
[CF3] FLOAT
EXECUTE @STR
SET @i = @i + 1;
END
GO
As a result, an error message appears:
"The name 'CREATE TABLE SQL_DB_Filestream.dbo.Image1I1 (
[ID_RowFeatVec] INTEGER NOT NULL PRIMARY KEY' is not a valid identifier."
I have tried a lot of versions but it doesn't work.
What am I doing wrong?
Best wishes
SV_proj>> I have to create 10 tables with different names e.g. 'Image1', 'Image2', and so on. For this goal, I use a loop and concatenation. Here is the code: <<
1) An SQL Programmer would write ten CREATE TABLE statements. Are you old enough to know about Rube Goldberg? He was a cartoonist who invented inanely complex device for simple task!
2) Ten identical tables is a huge design flaw. It is so awful I want to use it in one of my books. Tables are sets. A set is completed whole, or as Cantor said “a many that is treated as a one” (it sounds cool in German or Esperanto).
3) We hate loops in SQL. This is a declarative language. I will bet you have no idea what that means.
What you want to do is mimic a magnetic tape file system from the 1950's. We used to put a label on the tapes based on the date or a sequence number. Not a completed whole.
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL -
How can join two tables if column values does not match
Hi guys,
i have table
col1 col2
abcd 123
asdf 234
wert 456
sedf 789
and another table with
col1
abcd
aaaa
but i need the output like
abcd 123
abcd 234
abcd 456
abcd 789
aaaa 123
aaaa 234
aaaa 456
aaaa 789You do not tell us about this where condition before, but...
select b.col1, a.col2 from table a, another_table b
where a.col2 in (123, 234, 456, 789)or
select b.col1, a.col2 from table a, another_table b
where a.col1 in ('abcd','asdf','wert','sedf' )
Maybe you are looking for
-
HD setup in Mac Pro to be used as Server
I've searched through the various hard drive posts here on the lists, and think I am actually more confused than I was before. We are currently running Tiger Server on a Dual 2 G5 and are preparing to migrate to Leopard Server on a new 8-core Mac Pro
-
When connecting an external amplifier
When connecting the headphione jack to external speakers through an external amplifier I am receiving a loud distortion sound. Can it be eliminated?
-
Macbook Pro Nvidia card sunddenly working
Last year I opened my Macbook pro and the screen wouldn't turn on. Completely black. The computer turned on, I can hear the start up noise and the fans running with keyboard lighting up, just not the screen. So I took it into AppleCare and they came
-
Cursor within cursor insert problem.
Hello, Am trying to pass a parameter from one cursor to another and making an insert in the 2nd cursor but its not inserting. declare v_txt_1 varchar2(10); v_txt_2 varchar2(10); cursor C1 is select txt1,txt2 from test1where country='INI'; cursor C2(p
-
Mac OSX cannot be upgraded to v.10.5 on your computer
I have a Macbook Pro that is 3 months old running 10.4.11. I am trying to upgrade to leopard and repeatedly get the error: Mac OSX cannot be upgraded to v.10.5 on your computer. / Mac OSX v.10.4 or later could not be found on your computer. Then when