Joining multiple tables in Oracle DB
I have the following tables.
1. AddProject
- projID
- projName
2. AddLab
- labID
- labName
3. ProjLabAssociation
- projID
- labID
4. AddResearchArea
- raID
- raName
5. ProjRAAssociation
- projID
- raID
AddProject is associated with both the tables-AddLab and AddResearchArea
ProjLabAssociation and ProjRAAssociation are association tables which contain the primary keys from corresponding tables. Both the fields in these 2 tables are primary keys.
If AddProject has 3 entries - (Proj1,ProjectA),(Proj2,ProjectB),(Proj3,ProjectC)
AddLab has 2 entries - (Lab1,Bangalore),(Lab2,Chennai)
AddResearchArea has 2 entries - (RA1,Green Computing),(RA2,Cloud Computing)
ProjLabAssociation has 2 entries - (Proj2,Lab1),(Proj3,Lab1)
ProjRAAssociation has 3 entries - (Proj2,RA1),(Proj3,RA1),(Proj3,RA2)
If I am querying by AddLab data for (Lab1,Bangalore), I should be getting the following columns in the result table
Table2ID | Table2Name | Table3ID | Table3Name | Table1ID | Table1Name
Lab1 | Bangalore | RA1 | Green Computing | Proj2 | ProjectB
Lab1 | Bangalore | RA1 | Green Computing | Proj3 | ProjectC
Lab1 | Bangalore | RA2 | Cloud Computing | Proj3 | ProjectC
I have been trying the following commands but I m getting the expected result
1.SELECT * FROM AddLab al, ProjLabAssociation pl, AddProject ap WHERE al.labID = pl.labID(+) and ap.projID = pl.projID(+);An SQLException is thrown saying - java.sql.SQLException: ORA-01417: a table may be outer joined to at most one other table
2.SELECT * FROM AddLab,AddProject,AddResearchArea WHERE labID in
(select al.labID from ProjLabAssociation pl,AddLab al where al.labID = pl.labID)
AND projID in
(select ap.projID from ProjLabAssociation pl,Addproject ap where ap.projID = pl.projID)
AND themeID in
(select ar.raID from ProjRAAssociation pr, AddResearchArea ar where ar.raID = pr.raID)
AND projID in
(select ap.projID from ProjRAAssociation pr,Addproject ap where ap.projID = pr.projID)
ORDER BY labID;I am not getting the expcted results here
Oracle version : 9i 10g/11g
Can anyone help me in this.
Edited by: user9205634 on Dec 22, 2011 3:40 AM
1. Always tell the community your Oracle version
2. If you want to learn, always show to the community you tries so far
3. Always use tags before and after your code to keep the code formatted on forum side
4. Post in the proper forum according to the question, in yuour case, <a href=PL/SQL & PL/SQL</a> (not Database General)
+=> thread moved there.+
Nicolas.
Similar Messages
-
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 -
Best way to import data to multiple tables in oracle d.b from sql server
HI All am newbie to Oracle,
What is the Best way to import data to multiple tables in Oracle Data base from sql server?
1)linked server?
2)ssis ?
If possible share me the query to done this task using Linked server?
Regards,
KoteRavindra.check:
http://www.mssqltips.com/sqlservertip/2011/export-sql-server-data-to-oracle-using-ssis/
koteravindra
Handle: koteravindra
Status Level: Newbie
Registered: Jan 9, 2013
Total Posts: 4
Total Questions: 3 (3 unresolved)
why so many unresolved questions? Remember to close your threads marking them as answered. -
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 -
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. -
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 -
How to build a form with multiple tables in oracle application express
Hi everyone,
I have got problem in building a form with multiple tables.I have a main table with (20) columns and this main table is related to the other tables with the primary key-foreign key relation ship.My requirement is i have to build a form which has fields from many tables and all the fields are related to the main table using (ID) column.In that form if i enter ID field i have to get information from differnt tables.
Please help me to solve this (building a form with mutiple tables)
Thank you
sansSans,
I am no Apex expert, but with a situation as "complex" as yours, have you thought about creating a VIEW that joins these 7/8 tables, placing an INSTEAD OF trigger on that view to do all the business logic in the database, and base your application on the view?
This is the "thick-database" approach that has been gaining momentum of late. The idea is to put your business logic in the database wherever possible, and let the application (Form, Apex, J2EE, whatever) concentrate on UI issues, -
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. -
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. -
Joining 2 tables in oracle database using SQL
I want to join 2 tables together before executing a statement.
problem is one is a table of users, who have userID's
and the othet table is a table of events that are owned by a userID, ie can have many events by same userID.
i want to retrieve forename and lastname from the users table, nd the event details from the event table, and put a name against each event rather than a userID, how can i do this?
note i want to extract EVERY SINGLE EVENT, and get the name of the user it is owned by via the userID
heres a example of a row
Table Users
| UserID | Forename | Surname |
| Y244850 | Jimmy | Conner |
| Y256738 | Mikey | Reeves |
Table Events
| UserID | Date | Type | Location |
| Y244850 | 07-Jan-01 | Holiday | Ibiza |
| Y244850 | 15-Dec-01 | Holiday | Jamaica |
------------------------------------------------Well just exchange user_id with u.user_ud or l.user_id:
SQL> SELECT forename, surname, TO_CHAR(id) id,
TO_CHAR(start_date) start_date, TO_CHAR(end_date)
end_date, type, u.user_id, location FROM leave_details l,
user_details u WHERE l.user_id = u.user_id;
When you just say select user_id, the database doesn't know wich user_id to use. The one in details or in users...
(Even though you and me know its the same)
So just be spesific and choose one.
Sjur -
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. -
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!!!
Maybe you are looking for
-
Blue Screen of Death with v.8 upgrade. Please help!!!
I tried upgrading to itunes v.8, but got blue screen of death. I've tried several times, with the same result. I tried suggestion on here...I went to itunes.exe and changed compatability to XP, but when I click it, it says there is a problem that nee
-
My lock screen picture is zoomed in. When I try to change it, I can't scale it, or try to zoom out to a position I like. It is permanently stuck in one position. I asked a friend that had ios7 and he can't relate, and has never seen it before. Any he
-
Outer/Cartesian Join using same table
Hi All, I'm needing to write a query, which is kind of like an outer join/cartesian join that essentially tags each customer in my database with a flag indicating whether they have received a particular product for a given year. There are 8 products
-
My Epson r340 printer is having gaps on my black ink even after cleaning several times. Funny is when doing the test print all the colors even the black ink would show all the lines coming out. If this can't be fixed I need a recommendation for a rep
-
Can I restore lost Reminders from a back up?
Hi, After connecting to iCloud last night and setting up my sync for Calendars, I noticed today that all my Reminders have disappeared. I looked on my iPad, also set up to sync, and it tantalisingly flashed up all my Reminders when I opened that app.