Join multiple tables(6 tables) without duplicates
Hi guys,
I am having a problem with SQL query. I have 6 tables (Product,Manufacturer, ProductSpecs, GeneralSpecs, ProductConf, GeneralConf)
1. Product and Manufacturer are referenced with ManufacturerID
2. ProductSpecs and GeneralSpecs are referenced with SpecID
3. ProductConf and GeneralConf are referenced with ConfID
4. Product,ProductSpecs and ProductConf are referenced with Product_ID
My requirement is to get the list of a particular product for each manufacturer with the list of unique Product Specification and Product Configuration. I had joined all the tables using LEFT OUTER JOIN, but i am getting numerous duplicate records. I need an efficient query so that I get all the information without any duplicates.
Thanks in advance
Arun
Avery wild guess!
Adjust the columns you want.
SELECT P.columns_youwant,
M.columns_youwant,
ps.both_ps_and_gs_colummns_youwant,
pc.both_pc_andgc_columns_youwant
FROM Product P,
Manufacturer M,
(SELECT ps.product_id,
ps.specid,
gs.columns_you_want
FROM ProductSpecs ps, GeneralSpecs gs
WHERE ps.specid = gs.specid(+)) ps,
(SELECT pc.productid,
pc.ConfID,
gc.columns_youwant
FROM ProductConf pc, GeneralConf gc
WHERE pc.ConfID = gc.ConfID(+)) pc
WHERE P.ManufacturerID = M.ManufacturerID(+)
AND P.prduct_id = ps.product_id(+)
AND P.product_id = pc.product_id(+)G.
Similar Messages
-
LEFT OUTER JOIN multiple tables - using the 9i syntax
I've always written my queries using the (+) operator for outer joins. I want to start using the new ANSI standard available in 9i. I can do it when I'm joining two tables in a simple query, but how does it work when I am joining multiple tables?
Here is an example of some SQL that works with the (+) outer join syntax. How can I convert this to use the LEFT OUTER JOIN syntax?
SELECT *
FROM audit_entry aue,
audit_table aut,
audit_statement aus,
audit_row aur,
audit_row_pkey aup1,
audit_row_pkey aup2
WHERE aue.audit_entry_id = aus.audit_entry_id
AND aut.table_name = 'TEST_AUDITING'
AND aut.table_owner = 'CLA_JOURNAL'
AND aus.audit_table_id = aut.audit_table_id
AND aur.audit_statement_id (+) = aus.audit_statement_id
AND aup1.audit_row_id (+) = aur.audit_row_id
AND aup1.pk_column_name (+) = 'TEST_AUDTING_PK_1'
AND aup2.audit_row_id (+) = aur.audit_row_id
AND aup2.pk_column_name (+) = 'TEST_AUDITING_PK_2'
I can join audit_statement to audit_entry easy enough, but then I want to join audit_table to audit_statement, how do I do that, do I start nesting the join statements?
Thanks
RichardThanks for getting back so quickly, I have tried the suggested SQL with mixed results:
SELECT COUNT(*)
FROM audit_entry aue
JOIN audit_statement aus ON aue.audit_entry_id = aus.audit_entry_id
JOIN audit_table aut ON aus.audit_table_id = aut.audit_table_id
RIGHT OUTER JOIN audit_row aur ON aur.audit_statement_id = aus.audit_statement_id
RIGHT OUTER JOIN audit_row_pkey aup1 ON aup1.audit_row_id = aur.audit_row_id
RIGHT OUTER JOIN audit_row_pkey aup2 ON aup2.audit_row_id = aur.audit_row_id
WHERE aut.table_name = 'TEST_AUDITING_TWO'
AND aut.table_owner = 'CLA_JOURNAL'
AND aup1.pk_column_name = 'TEST_AUDTING_PK_1'
AND aup2.pk_column_name = 'TEST_AUDITING_PK_2'
I had to change the order slightly, between the first two JOINs but otherwise it executed OK. My problem is, it should only return 175 rows but its returning 30625 rows. If I comment out the second reference to audit_row_pkey I get the expected result:
SELECT COUNT(*)
FROM audit_entry aue
JOIN audit_statement aus ON aue.audit_entry_id = aus.audit_entry_id
JOIN audit_table aut ON aus.audit_table_id = aut.audit_table_id
RIGHT OUTER JOIN audit_row aur ON aur.audit_statement_id = aus.audit_statement_id
RIGHT OUTER JOIN audit_row_pkey aup1 ON aup1.audit_row_id = aur.audit_row_id
--RIGHT OUTER JOIN audit_row_pkey aup2 ON aup2.audit_row_id = aur.audit_row_id
WHERE aut.table_name = 'TEST_AUDITING_TWO'
AND aut.table_owner = 'CLA_JOURNAL'
AND aup1.pk_column_name = 'TEST_AUDTING_PK_1'
--AND aup2.pk_column_name = 'TEST_AUDITING_PK_2'
It looks the same condition is being used in each case but why do I suddenly get so many rows - its joining differently somehow. It must be to do with the order, do I need to bracket the query?
Thanks again
Richard -
Need Help on Joining multiple tables in Golden Gate
Hi,
Can you please help me with some examples on joining multiple tables in Golden Gate. i.e, my requirement is to Join Table 1 & Table 2 in Source and Load it in Target with 10 fields from Table 1 & 5 fields from Table 2 based on the join condition between Table 1.key = Table2.key
I have been trying to do that using SQLEXEC command in Golden Gate. But, is there a way I can do this in the Extract parameter file?
Thanks for your time
Regards
SureshHi,
Thanks a lot for the prompt reply. I am able to do that for the below scenario
Source.T1.Field1
Source.T1.Field2
Source.T2.Field1
Source.T2.Field2
Target Table
T1.Field1, T1.Field2, T2.Field1, T2.Field2.
But, if I already have T2.Field1 in T1 table, then T1.Field1 takes the precendence and getting loaded. i.e., I wanted to join the table 1 & Table 2 and based on the matching condition, I will need to populate the data either from T1 or T2.
Hope you got my requirement.
Below the Data Dump file & Replicat File.
EXTRACT dpump
USERID ********, PASSWORD ********
RMTHOST *******, MGRPORT 7809
RMTTRAIL /oracle/gg/dirdat/rt
--PASSTHRU
TABLE TABLE1,
SQLEXEC (ID LOOKUP,
QUERY "SELECT FIELD1 FROM SOURCE.TABLE2 WHERE FIELD1 = :v_field1",
PARAMS ( v_field1 = field1 )),
TOKENS (tk_field_1 = @GETVAL (lookup.field1));
Replicat file
REPLICAT repjoin
ASSUMETARGETDEFS
HANDLECOLLISIONS
USERID *******, PASSWORD ********
MAP SOURCE.T1, TARGET TARGET.GG_TABLE_T1,
COLMAP ( USEDEFAULTS ,
field1 = @token ("tk_party_id"));
I eventually wanted to join like below.
select t1.field1, t1.field2, t2.field1 from t1, t2
where t1.field1 = t2.field1;
Thanks for your time again
Regards
Suresh -
Joining multiple tables in ssis
I have to join multiple tables like 10 of them and load the data into destination. I get like 66 million records after joining, I have tried two ways to joining and load the data. First way, I used SQL command in ole db source and wrote the query there but
this is taking forever to start, second way is used sort and merge join transformation and also used Issorted property where ever I can but as it requires multiple sort transformation it is time consuming.
Is there any other way I can load those 66 million records in less time??
Thanks,
sreeHi sree,
If you want to load 66 million records to a SQL server database, the OLE DB Destination Editor allows us to choose either “Table or view” or “Table or view-fast load” from a drop down if data access mode is Table or View. “Table or view-fast load” is the
fastest way to load data to destination. It internally uses the bulk insert statement to send data into the destination table.
Besides, SSIS relies heavily on buffer. A set of records are read into the buffer, and from buffer they are written to the destination. So we can change two properties DefaultMaxBufferRows and DefaultMaxBufferSize to improve the performance. Also we can
add Conditional Split Transformation build some parallelism into the common data flow that directly load data to OLE DB Destination.
Reference:
http://henkvandervalk.com/speeding-up-ssis-bulk-inserts-into-sql-server
http://svangasql.wordpress.com/2012/04/10/simple-tips-to-speed-up-your-ssis-data-flow/
http://www.developer.com/db/top-10-methods-to-improve-etl-performance-using-ssis.html
Thanks,
Katherine Xiong
Katherine Xiong
TechNet Community Support -
How to join multiple tables !
Give me the Example to join multiple tables 1
Inner join
IF p_bsart IS INITIAL.
SELECT ekko~bukrs
ekko~lifnr
ekko~ebeln
ekko~waers
ekko~bsart
ekko~ekorg
ekko~ekgrp
ekpo~ebelp
ekpo~txz01
ekpo~matnr
ekpo~werks
ekpo~menge
ekpo~meins
ekpo~netpr
ekpo~netwr
INTO TABLE t_itab1 FROM
ekko INNER JOIN ekpo ON ekkoebeln = ekpoebeln
WHERE ekko~ebeln IN s_ebeln AND
ekko~bukrs IN s_bukrs AND
ekko~lifnr IN s_lifnr AND
ekko~ekorg IN s_ekorg AND
ekko~ekgrp IN s_ekgrp AND
ekpo~matnr IN s_matnr.
The difference between an INNER JOIN and an OUTER JOIN is the following. If a query on an INNER JOIN of VBAK (outer table) and VBAP (inner table) finds a record in VBAK but no matching records in VBAP, then no data is retrieved from the database because the inner table is empty. If you still want to keep VBAK rows for which there are no matching VBAP rows, you need to use the OUTER JOIN construct available in ABAP/4 Open SQL in 4.x..
Hi
Syntax
... [(] {dbtab_left [AS tabalias_left]} | join
{[INNER] JOIN}|{LEFT [OUTER] JOIN}
{dbtab_right [AS tabalias_right] ON join_cond} [)] ... .
Effect
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 language elements may not be used: BETWEEN, 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.
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. -
Select from multiple tables without join statement
Hey Gurus,
I would like to make a select from a multiple tables to check if there is any reference to my data. I would like to do it with some elegancy, but I don't know how.
Is in abap sql possible to do it only with the select statement?
Or I was also think about a solution that I should fill some data structure with all of the tables which I want to select from and then just loop that data structure and do the select seperately from all of the tables. I just need to check if it founds some results, so no need to store it. If this solution would be fine what data structure should I use?
Or can tell me what would be the best for this?
My code for select from one table, which I want to make for multiple tables:
SELECT SINGLE id_kniznice FROM zbr_t_autori INTO wa_id
WHERE id_kniznice EQ ls_extract-zview-id_kniznice.
IF sy-dbcnt > 0.
MESSAGE i000(zbr_msgc_lib).
ls_extract-flags-vim_mark = '*'.
MODIFY extract FROM ls_extract.
ENDIF.
Thank you for any posts.
Regards,
RobertAnd there we go again...
Read this topic:
For All Entries is NOT better than INNER JOIN in most cases
And this one:
inner join vs for all entries
Also that one:
Re: LOOP AT vs INNER JOIN
JOINs are really better than for all entries in most cases. Problem is people tend to ignore basic things like using pks or indexes while making them. -
Join multiple tables across separate databases
I needed to perform a join on multiple tables in two separate databases. I am using Sybase ASE 12.5 and jConnect 5.5 JDBC driver.
Table A is in DB1 and Table B is in DB2. Both DB1 and DB2 reside on the same database server.
I have set up JNDI bound datasources DS1 for DB1 and DS2 for DB2.
If the queries involved single tables or multiple tables within the same database, it is simple. But I am not seeing any way where I can perform a join between Tables A and B, which reside in separate databases. The datasources DS1 and DS2 are associated with DB1 and DB2 respectively, so I am not sure if there is anything like performing joins using two data sources.
One alternative I am facing is using a stored procedure in one database refer the table in the other database, for the join. But I may not be allowed to modify the database; currently, I am allowed to perform READ-ONLY queries.
So I am looking for any and all options. Please advice.
Thanks!Two choices..
One find the syntax in DB2 that allows you to do what you want in there. That would often be somelike...
select a.myfield
from database1.table1 a, database2.table2 b
where a.id = b.id
Obviously the database itself must support this. If it doesn't then you have choice two.
You extract the data from database1 using java for table1.
You extract the data from database2 using java for table2.
You write java code that merges the data from both sources. -
Join Multiple Tables in Forms 9i
I am attempting to create a tabular form in 9i using two tables. The tables have a one-to-many relationship. The Detail table is the main table for the form and I wish to pull in a column from the master table.
It is similar to the example provided in the on-line help for FORMS 9i 'JOIN of Multiple Tables'. I have gone through all the steps provided. The form compiles OK, however, when I execute_query I get the following error message 'FRM-40505: ORACLE error: unable to perform query.' It does not matter whether the form is of type form or tabular.
If I create a tabular form using the DETAIL table ONLY and then execute_query - the form works correctly.
Thank you in advance of any help
Michael RedfordAndrew, Thank you for your reply.
I concur as I have double checked everything and the Query now works. However I still have a problem.
The error 'FRM-40657 Record changed or deleted by another user' appears as soon as I attempt to change a users record. This form and system is still in development. No other developers/users have access to the tables or forms.
If I remove all references to the joined table then I can update the same field with no errors.
I am trying to display the users name where the users name is not a field on the current table.(similar to creating a form for Employees details and displaying the Department Name for each employee.)
Re: Display Error. We have very recently upgraded from Forms 6i to Forms9i. In 6i we used the Display Error in the Runtime Previewer to debug a Form. Forms 9i runs the form on the web and I'm not sure if the 'Display Error' feature is still available.
Thank you
Michael Redford -
Left Outer Joining multiple tables to one source table FAILS with VLD-1511
Hi all,
Is it me, or is OWB unable to handle left outer joining 1 source table to multiple other tables?
I want to load a fact table so I have 1 source table with measures. This table must be outer joined to some dimensions that have their FK in the fact table.
The SQL statement would look like this (and is perfectly valid):
select ...
from input, dim1, dim2
where input.c1 = dim1.c1(+)
and input.c2 = dim2.c2(+);
I put the where clause in the joiner operator and validate, but that gives me message VLD-1511: A table may be outer joined to at most one other table.
Even splitting this up into one outer join per joiner still gives this message.
A search and look around on the forum and on metalink shows there are related issues (like bug 3334035). Seemingly creating a view is the work-around to use.....? (ie downgrading owb to a simple gui tool) }-;
Have other people experienced this problem of not being able to outer join one input table to multiple other tables?
Thanks,
EdI have had some feedback from Oracle. It turns out this has to do with 2 issues. Below I have pasted the text that Support gave me:
<---------- START QUOTE ---------->
RESEARCH
=========
Bug 3437036 KEY LOOKUP DOES NOT DETECT ORA-1417 IN VALIDATE/GENERATE STEP
Unpublished Bug 4211684 FORWARD PORT OF BUG 3437036
shows:
Some more development has been completed when this bug is fixed in Paris.
The following are the details:
1. If the join condition contains a full outer join such as
tab1.c (+) = tab2.c (+) and tab2.c (+) = tab3.c
then the new validations implemented for this bug do not apply since
in OWB, full outer join triggers generation of joins in ANSI syntax.
ANSI syntax does not have the original problem the base bug of this
bug reported.
2. If the join condition does not contain any full outer join condition,
then the join is generated in Oracle join syntax, which is subject two
several restrictions. The fix to this bug check two of the restrictions.
3. The first restriction in Oracle syntax is that the outer join operator
"(+)" can only directly be attached to a column name. If you attach it
to an expression, such as the following:
(tab1.c + 1) (+) = tab2.c
Then there will be an ORA-936 error at the time of mapping deployment.
For this case, I have added a validation message VLD-1512 to error out
this situation.
4. The second restriction in Oracle syntax is that a table can only be
outer joined to exactly one other table.
For example, this is an invalid join in Oracle syntax:
tab1.c (+) = tab2.c and tab1.d (+) = tab3.d
because tab1 is left outer joined to tab2 and tab3.
But note that the following is still valid in Oracle syntax:
tab1.c (+) = tab2.c and tab1.d = tab3.d (+)
because tab1 is left outer joined to tab2 and right outer joined to tab3.
So this latter case does not violate the restriction that "same oj" to
more than 1 table is not allowed.
If same oj to more than 1 table is specified in a join condition,
VLD-1511 will be issued, and the map is made invalid.
<---------- END QUOTE ---------->
OWB does a partial validation, ie not all access paths are (can be) checked. A full check is only done by the database itself. So some scenarios (like checking whether multiple tables are outer joined the correct way) are not checked, and in this case are flagged with an error (even though it is actually a correct scenario).
Seemingly this was not flagged with an error in earlier versions of OWB, so beware, OWB behaviour may change when upgrading...
Alternative solutions are (1) using key lookups, (2) using a view with all outer joins in there, (3) using intermediate result tables between the joins.
Hope this info helps some people prevent spending too much time on a false error message,
Ed -
Dear Oracle guru's
This is seems to be simple but i couldnt get it right.
I am exploring the features of Oracle 10g and try to implement it .
the thing is how to Join 3 or more tables using the JOIN operator
traditionally we use the following select statement
consider the following tables
EMP table --(Empno,Ename,Deptno,Job,Sal,Grade)
Dept Table (deptno,Dname,Location)
Salgrade (Grade,Gname,Highsal,Lowsal)
Select empno,ename ,dname,Gname
from Emp E ,Dept D,salgrade S
where E.deptno = d.deptno
and e.grade =s.grade
I find this very easy ... but i have been asked to implement new things
how do we do this using 10g's Join
If we have to join two tables like EMP and DEPT i found out from oracle documentation
Select empno,ename,dname
from emp join dept using(deptno)
select empno, ename ,dname from emp e join dept d on e.deptno= d.deptno
Also if i have to do left outer join , i am comfortable with the traditional method of using (+) when using multiple tables
but how to do this using the LEFT OUTER JOIN when i have to join 3 or more tables of which 2 tables have LEFT OUTER JOIN
Consider the following
Select cc.cont_no, cc.instal_no,cc.instal_date , cc.instal_amt
From Cc_Instal_Stru cc,
Dc_Instal_Adj_Dtls dc
Where cc.cont_no = 230300
And cc.cont_no = dc.cont_no(+)
And cc.instal_no = dc.instal_no(+)
how do we go about it using the left outer join ?
With Warm Regards
ssrYes, you really posted this in the wrong forum.
The Join operator is just a different way of restating the SQL that you have done before.
When going with 3 tables, as in your example, you do as something like this -
SELECT empno, ename, dname, Gname
FROM ( Emp E
JOIN
Dept D
On E.deptno = d.deptno)
JOIN
Salgrade S
On E.grade = S.grade
This just makes it clearer what you are really joining on. When using the WHERE clause to specify the joins, you have to think some about what is going on as you try to read the SQL statement.
If wanting to do a LEFT OUTER JOIN, replace the word JOIN with the words LEFT OUTER JOIN (which you have to admit is clearer than the (+) that we have used in the past in explaining what is really happening).
Hope this helps a bit.
John Dickey -
JOIN question... Join two tables without omiting rows
I ran into a problem that should have an easy solution (I hope), but I'm having a hard time coming up with a solution.
Basically, I have two tables, one with actual amounts and one with the budget. I am to write a sql select statement that joins these tables together and includes all of their rows. I've been able to join the tables together using JOIN, LEFT JOIN, and RIGHT JOIN, but it always omits rows that I need.
Below, I have examples of my tables (AMOUNT_TABLE and BUDGET_TABLE). For simplicity sake, I've built the examples to show the same values in the first four columns, with the 5th and 6th columns (SUB_ACCOUNT, AMOUNT, BUDGET) as the only values that are different. My actual tables aren't quite as simple, but I didn't think it was relavent for this question.
AMOUNT_TABLE
FISCAL_YEAR
PERIOD
ACCT_UNIT
ACCOUNT
SUB_ACCOUNT
AMOUNT
2013
1
11111
555555
0000
100
2013
1
11111
555555
1000
100
2013
1
11111
555555
2000
100
2013
1
11111
555555
3000
100
2013
1
11111
555555
4000
100
BUDGET_TABLE
FISCAL_YEAR
PERIOD
ACCT_UNIT
ACCOUNT
SUB_ACCOUNT
BUDGET
2013
1
11111
555555
3000
200
2013
1
11111
555555
4000
200
2013
1
11111
555555
5000
200
2013
1
11111
555555
6000
200
Here is the output I'm hoping for. Notice that SUB_ACCOUNTs 0000, 1000, and 2000 show amounts with no budget since there isn't a matching row in the BUDGET_TABLE. And likewise, for SUB_ACCOUNTs 5000 and 6000, they show budgets with no amounts since there isn't a matching row in the AMOUNT_TABLE.
(output)
FISCAL_YEAR
PERIOD
ACCT_UNIT
ACCOUNT
SUB_ACCOUNT
AMOUNT
BUDGET
2013
1
11111
555555
0000
100
0
2013
1
11111
555555
1000
100
0
2013
1
11111
555555
2000
100
0
2013
1
11111
555555
3000
100
200
2013
1
11111
555555
4000
100
200
2013
1
11111
555555
5000
0
200
2013
1
11111
555555
6000
0
200
Hopefully, my question is clear. Any help on this would be greatly appreciated. Thanks in advance.Use ANSI join syntax - FULL OUTER JOIN:
with amount_table as (
select 2013 fiscal_year,1 period,11111 acct_unit,555555 account,0000 sub_account,100 amount from dual union all
select 2013,1,11111,555555,1000,100 from dual union all
select 2013,1,11111,555555,2000,100 from dual union all
select 2013,1,11111,555555,3000,100 from dual union all
select 2013,1,11111,555555,4000,100 from dual
budget_table as (
select 2013 fiscal_year,1 period,11111 acct_unit,555555 account,3000 sub_account,200 budget from dual union all
select 2013,1,11111,555555,4000,200 from dual union all
select 2013,1,11111,555555,5000,200 from dual union all
select 2013,1,11111,555555,6000,200 from dual
select nvl(a.fiscal_year,b.fiscal_year) fiscal_year,
nvl(a.period,b.period) period,
nvl(a.acct_unit,b.acct_unit) acct_unit,
nvl(a.account,b.account) account,
nvl(a.sub_account,b.sub_account) sub_account,
nvl(a.amount,0) amount,
nvl(b.budget,0) budget
from amount_table a
full join
budget_table b
on (
a.fiscal_year = b.fiscal_year
and
a.period = b.period
and
a.acct_unit = b.acct_unit
and
a.account = b.account
and
a.sub_account = b.sub_account
FISCAL_YEAR PERIOD ACCT_UNIT ACCOUNT SUB_ACCOUNT AMOUNT BUDGET
2013 1 11111 555555 0 100 0
2013 1 11111 555555 1000 100 0
2013 1 11111 555555 2000 100 0
2013 1 11111 555555 3000 100 200
2013 1 11111 555555 4000 100 200
2013 1 11111 555555 6000 0 200
2013 1 11111 555555 5000 0 200
7 rows selected.
SQL>
SY. -
Joining multiple tables using ANSI join
Hi,
I need to join 4 tables using ANSI join. Lets say they are A,B,C adn D. A and B has a common column called x. C and D had a common column called y. I wrote a query like this
select * from A left outer join B on (A.x=B.x),
C left outer join D on (C.y =D.y)
its not working!!!
I need to use ANSI join.
can any body help me please???Hi,
But is there is any common column between A,C or B,C or D,A?
Let me know. -
Problem with Business Component when joining multiple tables
I have a table that contains foreign keys from 4 other tables. When I view the table in the Business Component Browser it only returns one record. But when i run the same query in toad it returns the correct number of records. I'm I missing something or is there a bug in the application module?
Could you be more specific?
Supply the query and tables' definitions.
Is it right that you have created a compound view from all of the five tables?
Base Table
-> FK_Table1
-> FK_Table2
If so, check, whether the wizard correctly generated the associations info in this VO's XML file.
Actually, you recognize this as soon as he generates the query : the where clause should show appropriate fields being connected.
Another question is if you want to use inner or outer joins to the referencing FK tables.
You may also be interested in seeing my earlier post:
"BC4J; VO Wizard & References for multiple usage of one table".
Petr
null -
Joining multiple tables across multiple data sources in MYSQL throws error
Hi all,
I have to join tables across multiples MYSQL databases
eg :
Table T1,T2 from DB1
Table T3 from DB2
Columns from T3 are aggregated ( dimensional column ).
Hence when i query using oracle answers ( say i have columns from T1,T2 and T3 ) , OBIEE tries to a query DB1 by having NULL for columns in T3
It uses cast(NULL as INTEGER ) for columns from T3 . But MYSQL throws an error because "cast(NULL as INTEGER )" is not supported by MYSQL.
I tried executing the query generated by OBIEE manually , if i try giving cast(NULL as SIGNED INTEGER ) , it works.
pasting the query for reference
select distinct D1.c2 as c1,
D1.c1 as c2,
cast(NULL as INTEGER ) as c3
from
(select distinct T87.title_id as c1,
T59.asin as c2
from
print_book_catalog T59 left outer join
title_authority T87 On T59.asin = T87.asin
where ( T59.asin = '0345378911' )
) D1
I am not able to find any config file to set this property ( and use signed integer instead of integer ) . Even DBFeatures.INI does not have relevant information.
Can someobody please help me solve this problem.Stijn,
Thank you for the article link. That was very helpful! It seems that I had a few things off as you do need the "This source should be combined with other sources at this level." checked. In my two table source columns for DATA_SOURCE I defined a literal ('086496' and '085597' for the other) in the Column Mapping tab. I pasted the following in the Fragmentation content, checking the "This source..." box on the Content tab:
eSIS.SANDBOX4_SCHOOLS.DATA_SOURCE = '086496'
And pasted the following into the WHERE clause, checking "Select distinct values" on the Content tab:
sandbox4."".OBIEE.NWOCA_SCHOOLS.SCHOOL_CODE = VALUEOF(NQ_SESSION."SCHOOL") AND sandbox4."".OBIEE.NWOCA_SCHOOLS.DATA_SOURCE = VALUEOF(NQ_SESSION."GROUP")
This took care of my user's security, utilizing the session variables in the WHERE clause. I am now able to generate reports that only one user can access from one data source and share that same report with another user who can only see data from the other data source.
Many thanks!!! -
There are two tables TBL1 and TBL2. For a SQL below:
select ...
from TBL1 t1, TBL2 t2
where t1.id = t2.id and t1.status='ACTIVE' and t1.city =p_city and t1.state=p_state;
Will ORACLE first evaluate t1.status, t1.city, and t1.state first to eliminate the unmatched records, then make the join? OR
oracle will first make the join, then eliminate the unmatched records based on the t1.status, t1.city, and t1.state conditions? OR
Else?
Thanks to help.
ScottWill ORACLE first evaluate t1.status, t1.city, and t1.state first to eliminate the unmatched records, then make the join? OR
oracle will first make the join, then eliminate the unmatched records based on the t1.status, t1.city, and t1.state conditions? OR
Else?
Without execution plan we can not say exactly. Firstly provide this. To join of two or more tables(your case t1 and t2) oracle firstly
identify which join method is best for this situation when parsing query based on statistics(object,system) and initialization parameters(like memory and optimizer).
Here is three join method
a) Nested loop
-In this case oracle consider one of the table as OUTER and another as INNER then server process well read blocks from OUTER table and every according rows
server process will check that row in INNER table
b) Hash join
-In this case oracle will create hash table in the memory(as optimal hash join which session`s PGA(~HASH_AREA_SIZE) has enough space) according one of the join
tables based on join keys and internal hash function then will read second table and using hashing mechanism will find relevant rows(as knowing probing hash table)
b) Sort-merge join.
In this case server process will sort both tables in the memory(in optimal variant) based on join columns and then merged these.
But here is also important access method. Which method oracle used for scanning OUTER or INNER tables? if this is FULL TABLE SCAN then it means oracle will read
all blocks of the table(under high water mark) and after that according FILTER option in execution plan oracle discard these rows. But if oracle choose INDEX RANGE scan then oracle will get need relevant rows using index and here will not any discarding(most cases) also you can see in execution plan like ACCESS word.
Maybe you are looking for
-
Hallo, I want to use mixed costing over plants. The same material is produced in plant 200 and in plant 210. Both plants are part is the same company. For US-GAAP reasons those materials have to have the same standard price for valuation of the stock
-
Query developement and se16 access on productive system
Hi, we are setting up an authorization concept on ERP2004s and our users asking for query development rights and se16 on our productive system. I think queries and se16 should be on the test system due to security reasons. Please post some feedback h
-
Performance problem of program RFITEMAP
Hello all, if I select my interval for company code largely, the program (RFITEMAP) is very slow. What I can make in this report, so that preformance becomes better. Example: ( selection criterion ) company code : 1 to 200 - > ver
-
Installing Inventory only agent on VMWare ESXi
Hello, did anybody manage to install the Inventory-only-Agent (V 11.2.3) on a VMWare ESXi 5.1-Server? We would like to collect the inventory data for our CMDB. When i start the installation i get the follwoing errors: /tmp # ./zenumia-install.sh -s m
-
Please check your internet connection or try again...
To whom it may concern: I tried to redeem a Nokia music voucher, and it said that the pin is invalid. I emailed Nokia support and they suggested I uninstall the OVI player, delete a few files and install it again. After I have done it, when I click o