Multiple joins between tables
Not sure that the title best describes this.
I've got two tables which I'll simplify here
t1 - building (BuildingCode, Reception, Porter, Manager)
A, 1, 3, 8
B, 2, 4, 9
C, 1, 4, 7
t2 - staff (ID, Name, Extn)
1, Dave, 3302
2, Chris, 3994
3, Claire, 3033
8, Simon, 3255
and i'd like to get a table out that looks like
A, Dave, 3302, Claire, 3033, Simon, 3255
B, Chris, 3994 etc.
select b.buildingCode, s.Name, s.Extn
from building b, staff s
where s.ID = b.Reception
would give me one set of details - how can i get all 3?
Do I need to do 3 queries - where s.ID = b.Reception, where
s.ID = b.Porter and where s.ID = b.Manager and then join the 3
tables together or is there a more direct route?
Many thanks
Michael
Now that I've had a chance to try the code I found that to
use the results on the page I needed aliases in the select part as
well - final code is
select t1.BuildingCode, r.Name as rname, r.Extn as rextn,
p.Name as pname, p.Extn as pextn, m.Name as mname, m.Extn as mextn
from t1, t2 r, t2 p, t2 m
where t1.Reception = r.ID
and t1.Porter = p.ID
and t1.Manager = m.ID
Similar Messages
-
Find the key for join between table "crhd" and "equi" for use field "answt"
I make program for read data from table "crhd" for print about machine report
but I can not find the key for link join to table "equi" for print field "answt" (acquistion value)
please help me find the key field for join between table "crhd" and "equi" for use field "answt"
thank you very much...This is how the Work Center is linked to a particular Equipment -
Functional - In IE03 ( view Equipments) You see the Work Center of a particular Equipment.
Technical - Go to view V_EQUI ( view of EQUI and EQUZ). Pass the Equipment number alongwith V_EQUI-PM_OBJTY = 'A' ( i,.e searching for the Object Type Work Center). In this way u ll get the V_EQUI-GEWRK - this is the Work Center ID.
You can pass this Work Center ID to CRHD. And you will get the Work Center text.
CRHD-OBJTY = 'A'
CRHD-OBJID = V_EQUI-GEWRK.
and u ll get the CRHD-ARBPL - this is the Work Center.
So u need to come backwards, alongwith ur CRHD-OBJTY and CRHD-OBJID , you pass the same to V_EQUI and u get the list of equipment numbers alongwith ur ANSWT(Acquisition value).
I guess it solves ur problem. -
1.1 query builder join between tables
In the latest Sql Developer.
I invoke the query builder and select multiple tables that have foreign keys between them. These foreign key relationships appear in the diagram (good job).
How do I make those relationship appear in the SQL that query builder returns to the sql worksheet. I shouldn't have to re-specify them on the where/criteria tab.
It would be nice if these relationships are defaulted in the joining of tables.I overlayed the pre-release versionsDo you mean you installed in the same directory?
Don't do that.
There's a system directory (sqldeveloper\sqldeveloper\system) which holds settings and everything, which very well might be corrupted to be used for a newer release.
Try deleting it, it will be regenerated at next startup. Or even better: re-install in another directory all together...
K. -
Multiple Joins between 2 folders - when change condition value
Hi
I have created a report that joins 3 tables. The join between 2 of them gave me the option of two possible joins. I selected one and the report runs OK.
There is a condition in the report that uses one of the fields from one of the tables that has multiple join paths.
If I change the value of the condition from e.g. field = 04 to field = 05, then I get the error 'multiple join paths between folders'.
If I disable the multiple join path detection it runs ok and the query matches the original one.
However, do you know why I would get this error by just changing the value within an existing condition where the join path was already selected?
Thanks
GBHi,
Everytime when you change the value of the column, discoverer re-generates the query and hence asks for the Multiple joins.
You can disable this option in Discoverer Desktop.
Go to Tools > Options > Advanced > Uncheck "Multilpe Join Path Detection".
Cheers!
Yogini -
ABAP query- unable to delete the join between tables
Im unable to delete the join between two tables. when i right clicked on the join then it gives two options:
1. Display join condition
2. Remove join condition
both these options are grey in color so i cant select them. how can i remove join?goto SQ02 and enter infoset and goto change mode agagin select change mode and click the join then select and delete link...
-
Multiple Joins Between Folders
Hi Gurus,
I have a fact table which contains multiple candidate fields that can be joined to a lookup table
2 folders
fact_table
lookup_table1
2 Joins are possible between the two folders
fact_table.code_combination_id -> lookup_table1.code_combination_id
fact_table.accrual_code_combination_id -> lookup_table1.code_combination_id
When I try to create a workbook and include fields from the fact table, then include fields from the lookup table it asks me to choose the join.
If I then want to add fields based on the second join it won't ask me which join to use in future. It appears to assume the first join is still in affect between the two folders for the report. I know I can create another folder using the same lookup table and move one of the existing joins from the current folder to the new folder. Am I missing something or is this the only way to go?
Regards,
JohnHi John,
Interesting issue. This is how we resolved it in my last job.
Folders created:
Fact table: AR Fact
Lookup folder: Code Combination Lookup
Lookup folder: Accrual Code Combination Lookup
Then join AR Fact to each lookup folder. Generally, point the lookup folder to the AR Fact folder when creating the joins. Discoverer will like that direction best. As additional code combination types are referenced, add additional code combination folders. All of those folders come from the same lookup table. The only thing that is different is the column joined to in AR Fact.
So, in the end, your joins would be:
Code Combination Lookup.code_combination_id -> AR Fact.code_combination_id
Accrual Code Combination Lookup.code_combination_id -> AR Fact.accrual_code_combination_id
Hope this helps.
Regards,
Nancy -
Crystal Report: Multiple Join in Table
Hi experts,
I have a problem adding a table in a report.
The layout I'm modifing is the Purchase Order (CR). The report contains the necessary tables linked via the Database Expert to OPOR master table.
I need to add the Vendor Item Code in the OSCN table. To reach he correct code I have TWO values: ItemCode and CardCode.
ItemCode is in the POR1 row, and CardCode is in OPOR table.
I tried to add the table and link CardCode between OPOR and OSCN, and the field ItemCode between POR1 and OSCN but crystal say me that, he cannot join a just joined table!
So, how can I add the table OSCN linked correctly in the existing report ti dislay the correct Vendor Item Code near the ItemCode from OITM?
Thanks for your answers.hi Jonny,
paste this to your SQL query window to create this Stored Procedure
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[YourSP_Name]
AS
BEGIN
SET NOCOUNT ON;
SELECT OPOR.DocNum, POR1.DocEntry, POR1.LineNum, POR1.ItemCode, OPOR.CardCode, OSCN.Substitute
FROM OPOR INNER JOIN
POR1 ON OPOR.DocEntry = POR1.DocEntry INNER JOIN
OSCN ON OPOR.CardCode = OSCN.CardCode AND POR1.ItemCode = OSCN.ItemCode INNER JOIN
OITM ON OSCN.ItemCode = OITM.ItemCode
ORDER BY POR1.DocEntry
END
GO
then call this stored procedure in Crystal report
regards,
Fidel -
SQL Server Multiple JOINS with Table Value Function - query never ends
I have a query with 4 joins using a table value function to get the data and when I execute it the query never ends.
Issue Details
- Table value function
CREATE FUNCTION [dbo].[GetIndicator]
@indicator varchar(50),
@refDate datetime
RETURNS
TABLE
AS
RETURN
SELECT
T1.Id ,T1.ColINT_1, T1.ColNVARCHAR_1 collate DATABASE_DEFAULT as ColNVARCHAR_1 ,T1.ColNVARCHAR_2 ,T1.ColSMALLDATETIME_1, T1.ColDECIMAL_1, T1.ColDECIMAL_1
FROM TABLE2 T2
JOIN TABLE3 T3
ON T2.COLFKT3 = T3.Id
AND T3.ReferenceDate = @RefDate
AND T3.State != 'Deleted'
JOIN TABLE4 T4
ON T2.COLFKT4 = T4.Id AND T4.Name=@indicator
JOIN TABLE1 T1
ON T2.COLFKT1=T1.Id
- Query
DECLARE @RefDate datetime
SET @RefDate = '30 April 2014 23:59:59'
SELECT DISTINCT OTHERTABLE.Id As Id
FROM
GetIndicator('ID#1_0#INDICATOR_X',@RefDate) AS OTHERTABLE
JOIN GetIndicator('ID#1_0#INDICATOR_Y',@RefDate) AS YTABLE
ON OTHERTABLE.SomeId=YTABLE.SomeId
AND OTHERTABLE.DateOfEntry=YTABLE.DateOfEntry
JOIN GetIndicator('ID#1_0#INDICATOR_Z',@RefDate) AS ZTABLE
ON OTHERTABLE.SomeId=ZTABLE.SomeId
AND OTHERTABLE.DateOfEntry=ZTABLE.DateOfEntry
JOIN GetIndicator('ID#1_0#INDICATOR_W',@RefDate) AS WTABLE
ON OTHERTABLE.SomeId=WTABLE.SomeId
AND OTHERTABLE.DateOfEntry=WTABLE.DateOfEntry
JOIN GetIndicator('ID#1_0#INDICATOR_A',@RefDate) AS ATABLE
ON OTHERTABLE.SomeId=ATABLE.SomeId
AND OTHERTABLE.DateOfEntry=ATABLE.DateOfEntry
Other details:
- SQL server version: 2008 R2
- If I execute the table function code outside the query, with the same args, the execution time is less the 1s.
- Each table function call return between 250 and 500 rows.Hi,
Calling function in general is a costly query. And definitely joining with a function 5 times in not an efficient one.
1. You can populate the results for all parameters in a CTE or table variable or temporary table and join (instead of funtion) for different parameters
2. Looks like you want fetch the IDs falling to different indicators for the same @Refdate. You can try something like this
WITH CTE
AS
SELECT
T1.Id ,T1.ColINT_1, T1.ColNVARCHAR_1 collate DATABASE_DEFAULT as ColNVARCHAR_1 ,T1.ColNVARCHAR_2 ,T1.ColSMALLDATETIME_1, T1.ColDECIMAL_1, T1.ColDECIMAL_1, T4.Name
FROM TABLE2 T2
JOIN TABLE3 T3
ON T2.COLFKT3 = T3.Id
AND T3.ReferenceDate = @RefDate
AND T3.State != 'Deleted'
JOIN TABLE4 T4
ON T2.COLFKT4 = T4.Id AND T4.Name=@indicator
JOIN TABLE1 T1
ON T2.COLFKT1=T1.Id
SELECT * FROM CTE WHERE Name = 'ID#1_0#INDICATOR_X' AND Name = 'ID#1_0#INDICATOR_Y' AND Name = 'ID#1_0#INDICATOR_Z' AND Name = 'ID#1_0#INDICATOR_W' AND Name = 'ID#1_0#INDICATOR_A' AND ReferenceDate = @RefDate.
Or you can even simplify more depends on your requirement.
Regards,
Brindha. -
Dynamic SQL Joining between tables and Primary keys being configured within master tables
Team , Thanks for your help in advance !
I'm looking out to code a dynamic SQL which should refer Master tables for table names and Primary keys and then Join for insertion into target tables .
EG:
INSERT INTO HUB.dbo.lp_order
SELECT *
FROM del.dbo.lp_order t1
where not exists ( select *
from hub.dbo.lp_order tw
where t1.order_id = t2.order_id )
SET @rows = @@ROWCOUNT
PRINT 'Table: lp_order; Inserted Records: '+ Cast(@rows AS VARCHAR)
-- Please note Databse names are going to remain the same but table names and join conditions on keys
-- should vary for each table(s) being configured in master tables
Sample of Master configuration tables with table info and PK Info :
Table Info
Table_info_ID Table_Name
1 lp_order
7 lp__transition_record
Table_PK_Info
Table_PK_Info_ID Table_info_ID PK_Column_Name
2 1 order_id
8 7 transition_record_id
There can be more than one join condition for each table
Thanks you !
Rajkumar YeluguHi Rajkumar,
It is glad to hear that you figured the question out by yourself.
There's a flaw with your while loop in your sample code, just in case you hadn't noticed that, please see below.
--In this case, it goes to infinite loop
DECLARE @T TABLE(ID INT)
INSERT INTO @T VALUES(1),(3),(2)
DECLARE @ID INT
SELECT @ID = MIN(ID) FROM @T
WHILE @ID IS NOT NULL
PRINT @ID
SELECT @ID =ID FROM @T WHERE ID > @ID
So a cursor would be the appropriate option in your case, please reference below.
DECLARE @Table_Info TABLE
Table_info_ID INT,
Table_Name VARCHAR(99)
INSERT INTO @Table_Info VALUES(1,'lp_order'),(7,'lp__transition_record');
DECLARE @Table_PK_Info TABLE
Table_PK_Info_ID INT,
Table_info_ID INT,
PK_Column_Name VARCHAR(99)
INSERT INTO @Table_PK_Info VALUES(2,1,'order_id'),(8,7,'transition_record_id'),(3,1,'order_id2')
DECLARE @SQL NVarchar(MAX),
@ID INT,
@Table_Name VARCHAR(20),
@whereCondition VARCHAR(99)
DECLARE cur_Tabel_Info CURSOR
FOR SELECT Table_info_ID,Table_Name FROM @Table_Info
OPEN cur_Tabel_Info
FETCH NEXT FROM cur_Tabel_Info
INTO @ID, @Table_Name
WHILE @@FETCH_STATUS = 0
BEGIN
SELECT @whereCondition =ISNULL(@whereCondition+' AND ','') +'t1.'+PK_Column_Name+'='+'t2.'+PK_Column_Name FROM @Table_PK_Info WHERE Table_info_ID=@ID
SET @SQL = 'INSERT INTO hub.dbo.'+@Table_Name+'
SELECT * FROM del.dbo.'+@Table_Name+' AS T1
WHERE NOT EXISTS (
SELECT *
FROM hub.dbo.'+@Table_Name+' AS T2
WHERE '+@whereCondition+')'
SELECT @SQL
--EXEC(@SQL)
SET @whereCondition = NULL
FETCH NEXT FROM cur_Tabel_Info
INTO @ID, @Table_Name
END
Supposing you had noticed and fixed the flaw, your answer sharing is always welcome.
If you have any question, feel free to let me know.
Eric Zhang
TechNet Community Support -
what is wrong :
SELECT viser02~sdaufnr
FROM (viser02 INNER JOIN vbak
ON vbakvbeln = viser02sdaufnr
AND vbakposnr = viser02posnr
INNER JOIN vbap
ON vbapvbeln = viser02sdaufnr
AND vbapposnr = viser02posnr)
where vbak~auart = 'WV'
and ( vbap~sobkz <> 'V'
OR vbap~sobkz <> 'W' ).Hi,
Write the join as follows
DATA: BEGIN OF ITAB_AUFNR OCCURS 0,
SDAUFNR LIKE VISER02-SDAUFNR,
END OF ITAB_AUFNR.
SELECT viser02~sdaufnr
INTO TABLE ITAB_AUFNR
FROM viser02
INNER JOIN vbak
ON vbakvbeln = viser02sdaufnr
INNER JOIN vbap
ON vbapvbeln = viser02sdaufnr
AND vbapposnr = viser02posnr
where vbak~auart = 'WV'
and ( vbapsobkz <> 'V' OR vbapsobkz <> 'W' ).
The problem with your join is in VBAK there will not be any item field(POSNR) and you also didn't specify the into clause.
As a best practice do not use negative conditions in where cluases, they will consume more time. There will be two options to eliminate this.
1. Populate ranges table with all the allowed values for the SOBKZ field and use it in where clause.
OR
2. Populate ranges table with the not required values with the sign option 'E' (Exclude).
If you need any further help let me know.
Thanks
Giridhar -
Performing multiple joins on table
Hi all,
I would like to know if performing joins on more than 10 tables has some performance issues? If so, is there any limit on the joins that can be done?
Is there another way out for this problem?Rob Burbank wrote:>
> >
Thomas Zloch wrote:
> > If I had to bet, I'd say no, not included...do you have time to try out with a little test program?
> Probably not so little, but maybe sometime. I know there are standard SAP views with upwards of 13 or 14 tables, but I doubt if they would be compatable for joining.
>
> Rob
How about a self join? -
Multiple foreign key joins between two tables
Hi,
I have a question about building a repository.
I have a date dimension and one fact. The fact table has about 10 foreign key columns that link to the date Dimension.
In this case should I create 10 aliases to create joins in the Physical and BMM layer or is there any other way to handle this situation.
I am asking this question because 10 aliases can get very confusing for me at the later point of time while creating reports.
Using OBIEE 10.1.3Hi
I have a follow up question on this.
I am okay with not seeing the different date tables under the Subject area. Even if it just shows a it as a Simple DATE Dimension I am good with it.
In this case which is the efficient way, creating 10 aliases or creating 10 joins in the physical layer. I just figured out that we can create multiple joins between the same set of two tables but do not know how will that effect the way BI server works.
Please help me in understanding this concept.
thanks
This request id for OBIEE 10.1.3 -
Error: 38015, Physical tables have multiple joins.
Hi,
I have 5 dimensions and 1 fact table. One of the dimension table have 2 keys, which are referenced with fact table.
I have created aliases for all table on which I have defined joins.
But, It is giving me error like
ERRORS:
GLOBAL:
*[38015] Physical tables "obidb".."ORDER_DETAILS"."FACT" and "obidb".."ORDER_DETAILS"."BILLING_ACCOUNT" have multiple joins.*
Delete new foreign key object if it is a duplicate of existing foreign key.
Please give me any suggestions.....
Thanks.Hi,
Did your deleted existing foreign key before joining the alis_dim1(fk1), dim1(fk2) to fact join?
double check u r model its comes like circular join so by using alias method u r can resolve that issue.
In your model just check all your FK relation ship here u can find FK ending with #1 (double time just delete them and check metadata consitancey) if its not working delete the dimension and import it newly then create alias of the dim then join each other required fact also check below link
http://mtalavera.wordpress.com/2012/03/29/obieerpd-fails-global-consistency-on-joins-between-tables/
Thanks
Deva
Edited by: Devarasu on Nov 23, 2012 4:44 PM -
How To Find joins between siebel tables
Hi Experts,
I am new in siebel and i am working on BI reports.
I need to write queries to fetch data from sibel database.
Any idea how do we find joins between table in siebel. Is there any user guide??
Cheers,
AndyHi Andy,
We can find Joins in Object Explorer. Expand the Business Component Object in Object Explorer and you can find Join. In Siebel generally we use only Equi Joins. ROW_ID of parent table will be stored in PAR_ROW_ID of child table. ROW_ID and PAR_ROW_ID are the columns of the table. Most of the tables have these two columns.
For Example: Take two tables S_CONTACT AND S_CONTACT_X, the ROW_ID of S_CONTACT will be stored in PAR_ROW_ID of S_CONTACT_X table.
If you want to join these two tables the query will be like
"SELECT * FROM S_CONTACT CON, S_CONTACT_X CONX WHERE CON.ROW_ID = CONX.PAR_ROW_ID"
This query will return all the records from S_CONTACT_X which matches S_CONTACT table.
Thanks & Regards,
Vinodhkumar -
Join between Oracle and non-Oracle Database
We are working at a project with the follow architecture:
- 5 Databases (3 Oracle, 1 Sybase and 1 DB2);
- Session Bean like Session Facade Pattern;
- Entity Bean (BMP);
- OC4J (Oracle Container for J2EE);
The case is that we cannot make join between tables of different bases, for example, join with one table of Oracle and one other of DB2, therefore the customer does not possess tool midleware for this.
The idea that appeared was: we make a query in table XXX of Oracle and return a HashTable with its respective VO�s and Keys (PKs from the first query that will serve of base for the second query), later we have access the DB2 that one second collection would return, to inside make join of the application.
The problem is that with this solution, we will have fall in the performance. And we do not know if it is the best form.
Do you have any idea???
Thanks,
Eric SanderHi,
If you have different databases then the join has to be done in the VM (either by the appserver or by you).
If you want to do it yourself, I would try the following:
-write one DAO per business object (at least one per database)
-this DAO contains the specifics of its database
-return a hashtable of keys and VOs from one DAO (as you say you do?)
-in the other DAO, add a method "joinWith ( Hashtable foreignKeys )" that will return the join's result
-implement the method along these lines:
1. retrieve the candidate rows from the second DAO's tables (1 query execution)
2. put the keys in a new Hashtable, say "candidateKeys" (meaning 1 iteration over all results)
3. iterate over all elements of foreignKeys (1 iteration)
4. for each element, check if a key exists in "candidateKeys" (1 hash lookup, very fast)
5. add any such row to the result
This is called a hash join (Oracle does it internally if you do a join).
It is the fastest algorithm to do joins.
Best,
Guy
http://www.atomikos.com - JTA transaction manager
Maybe you are looking for
-
my ipad is still not working its come up with the gray background with i pad writte in the background and well it turned back off and wont let me do anything so ive tried again resetting it and now its saying the itunes on my sisters computer needs t
-
Vendor Master: Name, Street Address and PO Address
Hello SAP Gurus- I am working on a Vendor Master cleanup hopefully to streamline our Vendor Master Data. We have data in all fields of the vendor master for address and in effort to decide on what to do with the SAPScript for checks, we would like t
-
Issue with modplsql module in Oracle App server
Hello all, We are facing problems with one of our application screens which throws Page Not Found error. When we do a look up in error logs of apache , the following is displayed - [Mon Dec 18 12:01:22 2006] [error] [client 10.13.1.137] [ecid: 116644
-
Sending mail based on values in report
hi , i have i requirement like sending mails to user if the values in the report exceeds some threshold. and user should be able to configure these mail settinigs. can any just tell me wether it is possible or not. thanks and regards siva ganesh
-
How to create a portlet to upload/delete files into portal pages
I wanted to know if it is possible to create a simple UI wherein a user could choose a file from his HDD and upload it to the page as an item.I know this can be done by editing the page,but when the user clicks on edit he would have to use the defaul