SQL Joins & joining 4 tables help.
Post Author: n8than1
CA Forum: Data Connectivity and SQL
Hello, I'm trying to build a report to show orders shipped, and pull in costing information from my sales tables. I have 4 tables I'm using data from, and I'm linking my shipping master and shipping items tables by a left outer join on shipper number. I'm linking my sales master table and sales item table using a left outer join on sales order number. Now I need to link the 4 tables together, and everything I try spits out duplicate line items. I'm linking my shipping master table to sales order master using a inner join on sales order number. here is a copy of my query: SELECT "sorels"."fmatlcost", "sorels"."fsetupcost", "sorels"."flabcost", "sorels"."fovhdcost", "sorels"."forderqty", "shmast"."fshipdate", "shitem"."fshipqty", "shitem"."fpartno", "somast"."fusercode", "shmast"."fcbcompany" FROM (("<SQL Database>"."dbo"."somast" "somast" INNER JOIN "<SQL Database>"."dbo"."shmast" "shmast" ON "somast"."fsono"="shmast"."fcsono") LEFT OUTER JOIN "<SQL Database>"."dbo"."sorels" "sorels" ON "somast"."fsono"="sorels"."fsono") LEFT OUTER JOIN "<SQL Database>"."dbo"."shitem" "shitem" ON "shmast"."fshipno"="shitem"."fshipno" WHERE ("shmast"."fshipdate">={ts '2007-11-01 00:00:00'} AND "shmast"."fshipdate"<{ts '2007-11-30 00:00:01'}) AND "shitem"."fpartno" NOT LIKE 'PM%' ORDER BY "somast"."fusercode", "shmast"."fcbcompany"
Post Author: GraemeG
CA Forum: Data Connectivity and SQL
At a glance, the problem seems to be primarily that you are not giving enopugh information to your joins to limit the data displayed. If you added an order and shipment line number to the joins this may help. Just for fun, can you put the table structures here and I'll give it a whirl? Alternatively, email me a sample from all four tables and I'll put something together and send it back. Use graemeg AT falum DOT co DOT nz.
Cheers G
Similar Messages
-
SQL Join Three Tables DW MX2004 ASP
I'm trying to display records using three tables joined as
shown in the SQL code below. I'm getting "no data" message when I
test the result page from the search form. I'm using the advanced
Dreamweaver form to enter the SQL commands. I have never used this
feature of Dreamweaver before and I'm not sure if the code below
follows the way DW MX will understand what I'm trying to do. Below
is the code based on Standard SQL....not sure if DW compatible...
This is what I typed in the SQL box:
SELECT
ResourceSkillMapping.resourceSkillMapID,ResourceSkillMapping.skillID,
ResourceSkillMapping.competenceLevel,skill.skillname,resource.resourceName,resource.resour ceLoginId
FROM ResourceSkillMapping INNER JOIN Skill ON
ResourceSkillMapping.skillID = Skill.skillID
INNER JOIN Resource ON
ResourceSkillMapping.resourceSkillMapID =
Resource.resourceSkillMapID
WHERE (Skill.skillName = '%Skill_asp%') AND
(Resource.resourceLoginID = '%Agent_asp%')
AND (Resource.active = 1)
These is typed in the variables box:
Variable Default Runtime
Skill_asp 1 Request.QueryString("skillname")
Agent_asp 1 Request.QueryString("resourceLoginID")
I'm using asp and the "Get" url parameters in the search form
calling the result recordset in DW. I'm connecting to a SQL 2000
server. Is this notation DW correct? Am I joining the tables
correctly. The tables are ResourceSkillMapping, Skill and Resource.
All I need is to be able to search by ResourceLoginID and by
skillName on all active records (active=1). The plan is to be able
to click on a result record and go to a detail page to update the
"CompetencyLevel" field in the resourceSkillMapping table using the
update behavior in DW.
Please help as this project is due this Tue and have been
trying every posibility I could think so far....I have read all the
DW help facilities many pages on this and still keep getting the
"no data" message
Thank you,
Carlos
[email protected]>> WHERE (Skill.skillName = '%Skill_asp%') AND
(Resource.resourceLoginID =
>>'%Agent_asp%')
I would say that this is where your problem is. Change it to:
WHERE (Skill.skillName LIKE '%Skill_asp%') AND
(Resource.resourceLoginID
LIKE
'%Agent_asp%')
and your query should work, unless of course you are actually
searching for
2 strings that read %Skill_asp% and %Agent_asp% exactly.
Pat.
"ITCoreTeam" <[email protected]> wrote in
message
news:[email protected]...
> I'm trying to display records using three tables joined
as shown in the
> SQL
> code below. I'm getting "no data" message when I test
the result page from
> the
> search form. I'm using the advanced Dreamweaver form to
enter the SQL
> commands.
> I have never used this feature of Dreamweaver before and
I'm not sure if
> the
> code below follows the way DW MX will understand what
I'm trying to do.
> Below
> is the code based on Standard SQL....not sure if DW
compatible...
> This is what I typed in the SQL box:
>
> SELECT
>
ResourceSkillMapping.resourceSkillMapID,ResourceSkillMapping.skillID,
>
>
ResourceSkillMapping.competenceLevel,skill.skillname,resource.resourceName,resou
> rce.resourceLoginId
> FROM ResourceSkillMapping INNER JOIN Skill ON
ResourceSkillMapping.skillID
> =
> Skill.skillID
> INNER JOIN Resource ON
ResourceSkillMapping.resourceSkillMapID =
> Resource.resourceSkillMapID
> WHERE (Skill.skillName = '%Skill_asp%') AND
(Resource.resourceLoginID =
> '%Agent_asp%')
> AND (Resource.active = 1)
>
> These is typed in the variables box:
> Variable Default Runtime
> Skill_asp 1 Request.QueryString("skillname")
> Agent_asp 1 Request.QueryString("resourceLoginID")
>
> I'm using asp and the "Get" url parameters in the search
form calling the
> result recordset in DW. I'm connecting to a SQL 2000
server. Is this
> notation
> DW correct? Am I joining the tables correctly. The
tables are
> ResourceSkillMapping, Skill and Resource. All I need is
to be able to
> search by
> ResourceLoginID and by skillName on all active records
(active=1). The
> plan is
> to be able to click on a result record and go to a
detail page to update
> the
> "CompetencyLevel" field in the resourceSkillMapping
table using the update
> behavior in DW.
> Please help as this project is due this Tue and have
been trying every
> posibility I could think so far....I have read all the
DW help facilities
> many
> pages on this and still keep getting the "no data"
message
> Thank you,
> Carlos
> [email protected]
> -
SQL Join Three Tables DW MX2004
I'm trying to display records using three tables joined as
shown in the SQL code below. I'm getting "no data" message when I
test the result page from the search form. I'm using the advanced
Dreamweaver form to enter the SQL commands. I have never used this
feature of Dreamweaver before and I'm not sure if the code below
follows the way DW MX will understand what I'm trying to do. Below
is the code based on Standard SQL....not sure if DW compatible...
This is what I typed in the SQL box:
SELECT
ResourceSkillMapping.resourceSkillMapID,ResourceSkillMapping.skillID,
ResourceSkillMapping.competenceLevel,skill.skillname,resource.resourceName,resource.resour ceLoginId
FROM ResourceSkillMapping INNER JOIN Skill ON
ResourceSkillMapping.skillID = Skill.skillID
INNER JOIN Resource ON
ResourceSkillMapping.resourceSkillMapID =
Resource.resourceSkillMapID
WHERE (Skill.skillName = '%Skill_asp%') AND
(Resource.resourceLoginID = '%Agent_asp%')
AND (Resource.active = 1)
These is typed in the variables box:
Variable Default Runtime
Skill_asp 1 Request.QueryString("skillname")
Agent_asp 1 Request.QueryString("resourceLoginID")
I'm using asp and the "Get" url parameters in the search form
calling the result recordset in DW. I'm connecting to a SQL 2000
server. Is this notation DW correct? Am I joining the tables
correctly. The tables are ResourceSkillMapping, Skill and Resource.
All I need is to be able to search by ResourceLoginID and by
skillName on all active records (active=1). The plan is to be able
to click on a result record and go to a detail page to update the
"CompetencyLevel" field in the resourceSkillMapping table using the
update behavior in DW.
Please help as this project is due this Tue and have been
trying every posibility I could think so far....I have read all the
DW help facilities many pages on this and still keep getting the
"no data" message
Thank you,
Carlos
[email protected]I'm trying to display records using three tables joined as
shown in the SQL code below. I'm getting "no data" message when I
test the result page from the search form. I'm using the advanced
Dreamweaver form to enter the SQL commands. I have never used this
feature of Dreamweaver before and I'm not sure if the code below
follows the way DW MX will understand what I'm trying to do. Below
is the code based on Standard SQL....not sure if DW compatible...
This is what I typed in the SQL box:
SELECT
ResourceSkillMapping.resourceSkillMapID,ResourceSkillMapping.skillID,
ResourceSkillMapping.competenceLevel,skill.skillname,resource.resourceName,resource.resour ceLoginId
FROM ResourceSkillMapping INNER JOIN Skill ON
ResourceSkillMapping.skillID = Skill.skillID
INNER JOIN Resource ON
ResourceSkillMapping.resourceSkillMapID =
Resource.resourceSkillMapID
WHERE (Skill.skillName = '%Skill_asp%') AND
(Resource.resourceLoginID = '%Agent_asp%')
AND (Resource.active = 1)
These is typed in the variables box:
Variable Default Runtime
Skill_asp 1 Request.QueryString("skillname")
Agent_asp 1 Request.QueryString("resourceLoginID")
I'm using asp and the "Get" url parameters in the search form
calling the result recordset in DW. I'm connecting to a SQL 2000
server. Is this notation DW correct? Am I joining the tables
correctly. The tables are ResourceSkillMapping, Skill and Resource.
All I need is to be able to search by ResourceLoginID and by
skillName on all active records (active=1). The plan is to be able
to click on a result record and go to a detail page to update the
"CompetencyLevel" field in the resourceSkillMapping table using the
update behavior in DW.
Please help as this project is due this Tue and have been
trying every posibility I could think so far....I have read all the
DW help facilities many pages on this and still keep getting the
"no data" message
Thank you,
Carlos
[email protected] -
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 -
Help needed in using Pivot by joining 2 tables
Hello everyone,
I am very new to usage of Pivot that includes joining 2 tables. Below is the scenario and request your help in this regard.
Table1
ID1 Description
1 Stationary
2 Apparel
3 Home Decor
Note : ID1 is unique
Table2
ID2 ID1 Item
1 1 Book
2 1 Paper-A4
3 2 T-Shirt
4 1 Pencil
5 3 Flower Vase
Note : ID2 is unique
I am trying to get the below result set.
ID2 Stationary Apparel Home Decor
1 Book NULL NULL
2 Paper-A4 NULL NULL
3 NULL T-Shirt NULL
4 Pencil NULL NULL
5 NULL NULL Flower Vase
Please help in this regard.
Thanks in advance,
KiranJust guessing
SELECT id2,
CASE WHEN Description='Stationary'
THEN Item END [Stationary],
CASE WHEN Description='Apparel'
THEN Item END [Apparel],
CASE WHEN Description='Home
Decor' THEN Item END [ Home
Decor]
FROM t1 JOIN t2 ON t1.id1=t2.id1
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence -
Please help - Joining three tables and get row values into Column. Please help!
Hi,
There is a SourceTable1 (Employee) with Columns like EmployeeID,Name,DOB.
There is a sourcetable2 (EmployeeCode) with columns like EmployeeID,Code,Order.
There is a source table 3 #EmployeeRegioncode and its columns are (EmployeeID , RegionCode , [Order]
The target table 'EmployeeDetails' has the following details. EmployeeID,Name,DOB,Code1,Code2,Code3,Code4,regioncode1
regioncode2 ,regioncode3 ,regioncode4
The requirement is , the value of the target table columns the Code1,code2,code3 ,code4,code5 values should
be column 'Code' from Sourcetable2 where its 'Order' column is accordingly. ie) Code1 value should be the 'Code' value where [Order] column =1, and Code2 value should be the 'Code' value where [Order] =2, and so on.
Same is the case for Source table 3- 'Region code' column also for the columns regioncode1
regioncode2 ,regioncode3 ,regioncode4
Here is the DDL and Sample date for your ref.
IF OBJECT_ID('TEMPDB..#Employee') IS NOT NULL DROP TABLE #Employee;
IF OBJECT_ID('TEMPDB..#EmployeeCode') IS NOT NULL DROP TABLE #EmployeeCode;
IF OBJECT_ID('TEMPDB..#EmployeeDetails') IS NOT NULL DROP TABLE #EmployeeDetails;
---Source1
CREATE table #Employee
(EmployeeID int, Empname varchar(20), DOB date )
insert into #Employee VALUES (1000,'Sachin','1975-12-12')
insert into #Employee VALUES (1001,'Sara','1996-12-10')
insert into #Employee VALUES (1002,'Arjun','2000-12-12')
---Source2
CREATE table #EmployeeCode
(EmployeeID int, Code varchar(10), [Order] int)
insert into #EmployeeCode VALUES (1000,'AA',1)
insert into #EmployeeCode VALUES (1000,'BB',2)
insert into #EmployeeCode VALUES (1000,'CC',3)
insert into #EmployeeCode VALUES (1001,'AAA',1)
insert into #EmployeeCode VALUES (1001,'BBB',2)
insert into #EmployeeCode VALUES (1001,'CCC',3)
insert into #EmployeeCode VALUES (1001,'DDD',4)
insert into #EmployeeCode VALUES (1002,'AAAA',1)
insert into #EmployeeCode VALUES (1002,'BBBB',2)
insert into #EmployeeCode VALUES (1002,'CCCC',3)
insert into #EmployeeCode VALUES (1002,'DDDD',4)
insert into #EmployeeCode VALUES (1002,'EEEE',5)
---Source tbl 3
CREATE table #EmployeeRegioncode
(EmployeeID int, RegionCode varchar(10), [Order] int)
insert into #EmployeeRegioncode VALUES (1000,'xx',1)
insert into #EmployeeRegioncode VALUES (1000,'yy',2)
insert into #EmployeeRegioncode VALUES (1000,'zz',3)
insert into #EmployeeRegioncode VALUES (1001,'xx',1)
insert into #EmployeeRegioncode VALUES (1001,'yy',2)
insert into #EmployeeRegioncode VALUES (1001,'zz',3)
insert into #EmployeeRegioncode VALUES (1001,'xy',4)
insert into #EmployeeRegioncode VALUES (1002,'qq',1)
insert into #EmployeeRegioncode VALUES (1002,'rr',2)
insert into #EmployeeRegioncode VALUES (1002,'ss',3)
---Target
Create table #EmployeeDetails
(EmployeeID int, Code1 varchar(10), Code2 varchar(10),Code3 varchar(10),Code4 varchar(10),Code5 varchar(10) , regioncode1 varchar(10),
regioncode2 varchar(10),regioncode3 varchar(10),regioncode4 varchar(10))
insert into #EmployeeDetails VALUES (1000,'AA','BB','CC','','','xx','yy','zz','')
insert into #EmployeeDetails VALUES (1001,'AAA','BBB','CCC','DDD','','xx','yy','zz','xy')
insert into #EmployeeDetails VALUES (1002,'AAAA','BBBB','CCCC','DDDD','EEEE','qq','rr','ss','')
SELECT * FROM #Employee
SELECT * FROM #EmployeeCode
SELECT * FROM #EmployeeRegioncode
SELECT * FROM #EmployeeDetails
Can you please help me to get the desired /targetoutput? I have sql server 2008.
Your help is greatly appreciated.select a.EmployeeID,b.code1,b.code2,b.code3,b.code4,b.code5,c.Reg1,c.Reg2,c.Reg3,c.Reg4 from
#Employee a
left outer join
(select EmployeeID,max(case when [Order] =1 then Code else '' end) code1,
max(case when [Order] =2 then Code else '' end)code2,
max(case when [Order] =3 then Code else '' end)code3,
max(case when [Order] =4 then Code else '' end)code4,
max(case when [Order] =5 then Code else '' end)code5 from #EmployeeCode group by EmployeeID) b
on a.EmployeeID=b.EmployeeID
left outer join
(select EmployeeID,max(case when [Order] =1 then RegionCode else '' end) Reg1,
max(case when [Order] =2 then RegionCode else '' end)Reg2,
max(case when [Order] =3 then RegionCode else '' end)Reg3,
max(case when [Order] =4 then RegionCode else '' end)Reg4 from #EmployeeRegioncode group by EmployeeID) c
on a.EmployeeID=c.EmployeeID
Thanks
Saravana Kumar C -
Joining two tables, sql query
This is a newbie question! I would like to join two tables. Table_1 contains xml stylesheets:
id stylesheet doc
1 <xml stylesheet doc A>
2 <xml stylesheet doc B>
And Table_2 contains the XML documents that the stylesheets will transform:
id XML doc
1 <XML document 1>
1 <XML document 2>
1 <XML document 3>
2 <XML document 4>
2 <XML document 5>
I would like <xml stylesheet doc A> to transform only XML doc that have an id of 1, so I tried this sql statement:
select a.stylesheet_doc ,b.xml_doc from Table_1 a, Table_2 b where a.id=b.id and a.id=1;
This statement returns the rows I want (stylesheet doc with id equals 1, and xml_doc with id equals 1), but it pairs each xml document with a style sheet.
stylesheet doc A <XML document 1>
stylesheet doc A <XML document 2>
stylesheet doc A <XML document 3>
My question is, is there a way to have a result that looks like this?
stylesheet doc A
<XML document 1>
<XML document 2>
<XML document 3>
That is, is there a way in sql to get rid of duplicate stylesheet doc A?
I have tried group by and rollup and xmlagg.
Thank you very, very much for your help.
JimHi, Jim,
Welcome to the forum!
You just want to display the XML, not actually transform it, right?
GROUP BY ROLLUP should work, but I find it easier with GROUP BY GROUPING SETS. Here's an example from tables in the scott schema:
SELECT CASE
WHEN GROUPING (ename) = 1
THEN d.dname
END AS dname
, e.ename
FROM scott.dept d
JOIN scott.emp e ON d.deptno = e.deptno
GROUP BY GROUPING SETS ( (d.dname, e.ename)
, (d.dname)
ORDER BY d.dname
, ename NULLS FIRST
;Output:
DNAME ENAME
ACCOUNTING
CLARK
KING
MILLER
RESEARCH
ADAMS
FORD
JONES
SCOTT
SMITH
SALES
ALLEN
BLAKE
JAMES
MARTIN
TURNER
WARDYou may have noticed that this site noramlly compresses whitespace.
Whenever you post formatted text (such as query results) on this site, type these 6 characters:
\(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing. -
I need some help on my sql to join 3 tables.
I am close, but my results come out to be a multiple of what im supposed to get.
I am trying to retrieve a sum from table 2 and table 3.
there are 4 records in table2 and 3 records in table3
the results SHOULD be 3 and 20
but i get 12/60
which is a number i shoudl get times the #records of the oppposite table.
i have moved my code in different arrangements to see if that is the issue, but it doesnt seem to matter. i still get the result of a multiple.
Heres my code so far:
SELECT sum(table3.field) AS sumtable3, sum(table3.field) AS sumtable2
FROM table1
LEFT JOIN table2 ON table1.id=table2.id
LEFT JOIN table3 ON table2.id=table3.id
GROUP BY table1.id
ORDER BY table1.idPlease provide sample data for all 3 tables.
-
SQL Experts,
I have a query below. Can I improve the SQL joining order in highlighted section - Lines 31 to 40
SNIOTM.SNI_PA_OTM_ARC_DRVR -- around 200K rows
SNIOTM.SNI_PA_ORD_SHP_STATUS -- 8 rows
Edited by: 922411 on May 12, 2013 7:42 PM922411 wrote:
SQL Experts,
I have a query below. Can I improve the SQL joining order in highlighted section - Lines 31 to 40
SNIOTM.SNI_PA_OTM_ARC_DRVR -- around 200K rows
SNIOTM.SNI_PA_ORD_SHP_STATUS -- 8 rowsYou need not worry about the Joining Order, Oracle CBO is efficient enough to choose the Most Efficient way of joining the tables. However, it will depend on your Oracle Version, which you have not mentioned. If you are 10g or higher then you certainly need not worry.
If you sense a problem in performance of query, then I will suggest you read the linked threads in {message:id=9360003} and post the details as specified.
Only this will help us provide releavant suggestions and avoid guessing games.
PS:- Do not forget to post Oracle Version and the Explain Plan in {noformat}{noformat} tags, exactly as specified. -
I am trying to develop a query in MS Access 2010 to join two tables using three joins, one of which is a (between) date range. The tables are contained in Access. The reason
the tables are contained in access because they are imported from different ODBC warehouses and the data is formatted for uniformity. I believe this cannot be developed using MS Visual Query Designer. I think writing a query in SQL would be suiting this project.
ABCPART links to XYZPART. ABCSERIAL links to XYZSERIAL. ABCDATE links to (between) XYZDATE1 and ZYZDATE2.
[ABCTABLE]
ABCORDER
ABCPART
ABCSERIAL
ABCDATE
[ZYXTABLE]
XYZORDER
XYZPART
XYZSERIAL
XYZDATE1
XYZDATE2Thank you for the looking at the post. The actual table names are rather ambiguous. I renamed them so it would make more sense. I will explain more and give the actual names. What I do not have is the actual data in the table. That is something I don't have
on this computer. There are no "Null" fields in either of the tables.
This table has many orders (MSORDER) that need to match one order (GLORDER) in GLORDR. This is based on MSPART joined to GLPART, MSSERIAL joined to GLSERIAL, and MSOPNDATE joined if it falls between GLSTARTDATE and GLENDDATE.
[MSORDR]
MSORDER
MSPART
MSSERIAL
MSOPNDATE
11111111
4444444
55555
2/4/2015
22222222
6666666
11111
1/6/2015
33333333
6666666
11111
3/5/2015
This table has one order for every part number and every serial number.
[GLORDR]
GLORDER
GLPART
GLSERIAL
GLSTARTDATE
GLENDDATE
ABC11111
444444
55555
1/2/2015
4/4/2015
ABC22222
666666
11111
1/5/2015
4/10/2015
AAA11111
555555
22222
3/2/2015
4/10/2015
Post Query table
GLORDER
MSORDER
GLSTARTDATE
GLENDDATE
MSOPNDATE
ABC11111
11111111
1/2/2015
4/4/2015
2/4/2015
ABC22222
22222222
1/5/2015
4/10/2015
1/6/2015
ABC22222
33333333
1/5/2015
4/10/2015
3/5/2015
This is the SQL minus the between date join.
SELECT GLORDR.GLORDER, MSORDR.MSORDER, GLORDR.GLSTARTDATE, GLORDR.GLENDDATE, MSORDR.MSOPNDATE
FROM GLORDR INNER JOIN MSORDR ON (GLORDR.GLSERIAL = MSORDR.MSSERIAL) AND (GLORDR.GLPART = MSORDR.MSPART); -
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 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 two tables in PL/SQL
Hi there,
I have two problems...first being:
We are trying to run a sub-query within a WHERE/AND clause. I am not sure on the correct syntax on how to run the sub-query as denoted in the code below. Secondly I am trying to join two tables with a common column name (ie: CIPIDI_NR). Considering I cant fix the first problem I cant test out the sub-query. So any help on either would be grateful. Cheers
Select *
from TBL_CIPIDI
WHERE CIPIDI_NR like nvl ('in_case_number%', CIPIDI_NR)
AND CIPIDI_NAME like nvl ('in_case_name%', CIPIDI_NAME)
AND COST_CENTRE LIKE NVL ('in_cost_centre%', COST_CENTRE)
AND CIPIDI_DESCRIPTION like nvl ('in_description%', CIPIDI_DESCRIPTION)
AND CLAIMANT_NAME LIKE NVL ('in_claimant%', CLAIMANT_NAME)
AND REQUESTOR LIKE NVL ('in_requestor%', REQUESTOR)
AND PROJECT_MANAGER LIKE NVL ('in_project_manager%', PROJECT_MANAGER)
AND TEAM_LEADER LIKE NVL ('in_team_leader%', TEAM_LEADER)
AND ********RUN THE QUERY BELOW************
SELECT C1.CIPIDI_NR, C2.CIPIDI_NR
from TBL_TEAM_MEMBERS C1, TBL_CIPIDI C2
WHERE C1.CIPIDI_NR = C2.CIPIDI_NR
AND TEAM_MEM_NAME LIKE NVL ('in_team_mem_name%', TEAM_MEM_NAME)
);You really need to start providing create table and insert statements for tables and sample data for testing, the results that you want based on that data in order to clarify the problem, your Oracle version, and a copy and paste of an attempted run of your code, complete with any error messages received. The following is my best guess at what you might be looking for.
Select *
from TBL_TEAM_MEMBERS C1, TBL_CIPIDI C2
WHERE C1.CIPIDI_NR = C2.CIPIDI_NR
AND c1.CIPIDI_NR like nvl (in_case_number || '%', c1.CIPIDI_NR)
AND c1.CIPIDI_NAME like nvl (in_case_name || '%', c1.CIPIDI_NAME)
AND c1.COST_CENTRE LIKE NVL (in_cost_centre || '%', c1.COST_CENTRE)
AND c1.CIPIDI_DESCRIPTION like nvl (in_description || '%', c1.CIPIDI_DESCRIPTION)
AND c1.CLAIMANT_NAME LIKE NVL (in_claimant || '%', c1.CLAIMANT_NAME)
AND c1.REQUESTOR LIKE NVL (in_requestor || '%', c1.REQUESTOR)
AND c1.PROJECT_MANAGER LIKE NVL (in_project_manager || '%', c1.PROJECT_MANAGER)
AND c1.TEAM_LEADER LIKE NVL (in_team_leader || '%', c1.TEAM_LEADER)
AND TEAM_MEM_NAME LIKE NVL (in_team_mem_name || '%', TEAM_MEM_NAME); -
Adding a filter to an SQL Join table in OBIEE
Hello,
I have created a query in OBIEE Answers to Left outer join two tables. This all works fine but I would like to set this up as a dashboard and create a prompt. The problem I have is because this is not a subject area how can I create a prompt? I would like the prompt on B.saw_2
My query is below:
SELECT
A.saw_0,
B.saw_2
FROM
(SELECT
Employee."Employee Reference" saw_0
FROM
"Applications and Awards (Employee)"
WHERE (Employee."Employee Reference" LIKE 'MR/L%')) A
LEFT OUTER JOIN
(SELECT
Employee."Employee Reference" saw_0,
LEFT(Classification."Classification Id",10) saw_1,
Classification."Classification Name" saw_2
FROM
"Applications and Awards (Employee)"
WHERE (LEFT(Classification."Classification Id",10) LIKE 'CSMRBS%')) B ON A.saw_0 = B.saw_0
Thank you,
JohnHi John,
For direct database request ::::
Please create bind variable like sql at the position of the column you are going to or want to have the value prompted. ':xyz'.
For creating prompt choose any column from any subject area, remove the formula and put dual statement like select xyz from dual. This is your value which you are passing there.
For your logical query ::: you can use presentation variable '@{xyz}123'
Thanks,
Amol
(Please mark this answer, if you found correct) -
Joining two tables using PL/SQL
here i am trying to join two tables can any one tell me what is wrong with this syntex
CREATE OR REPLACE PROCEDURE test IS
CURSOR c1 IS SELECT seq,fname,lname from t1;
CURSOR c2 IS SELECT seq1,q,a from t2;
userjob number;
BEGIN
OPEN c1;
insert into t3 values(c1.seq,c1.fname,c1.lname);
FETCH c1.seq INTO userjob;
FOR c1rec IN c2 LOOP
IF (c1rec.seq=c1.seq and c1rec.q1='why') THEN
insert into t3 values(c1rec.q1,c1rec.a1);
elsif (c1rec.seq=c1.seq and c1rec.q1='what') then
insert into t3 values(c1rec.q2,c1rec.a2);
elsif (c1rec.seq=c1.seq and c1rec.q1='when') then
insert into t3 values(c1rec.q3,c1rec.a3);
elsif (c1rec.seq=c1.seq and c1rec.q1='where') then
insert into t3 values(c1rec.q4,c1rec.a4);
END IF;
END LOOP;
END;
/You should always fetch a cursor before using it's values. All columns in the select should be fetched into variables or a record-variable. You can't refer to the cursor-columns values with c1.seq etc.
r1 c1%rowtype;
l_found boolean;
BEGIN
OPEN c1;
FETCH c1 INTO r1;
insert into t3 values(r1.seq,r1.fname,r1.lname);
l_found := c1%found;
close c1;
if l_found
then
It is also better to close the cursor and check if the select resulted in a row. With this code you will only retrieve one row even if the select will result in multiple rows.
But I agree with all the others that this can probably be done more efficiently with one SQL statement.
Maybe you are looking for
-
How far does Oracle Support extend?
Hi, I have a problem determining how far I am covered by oracle support in a particular circumstance. I intend to use the DMBS_LDAP package to connect to a CAS authentication server. 1. Am I covered by Oracle Support in this scenario? 2. If I am cove
-
No fire wire function anymore?
Hello, I just bought the new Ipod 80 gig, and tbh I'm a bit disappointed in some changes. First of all, no firewire transfer is possible anymore. (I had a 3rd gen Ipod before I always used firewire it goes waaaaaay faster than USB 2.0) Or is there so
-
Dear Experts, In our setup we are only using FI-AP (No MM) we have enhanced field CIN in general section of vendor. Currently we wanted to update CIN information on all the vendors for which I created LSMW. I noticed that when batch map is created th
-
Migration export dvd missing in system copy process
Hi 1. We are doing system copy of XI 3.00 server that is based on SAP Web AS 6.40. 2. I'm following the "Homogeneous and Hetrogeneous system copy for SAP System based on SAp Web AS ABAp 6.40 patch collection" document. Document version is 1
-
Is it possible to move .emlx files to a new machine?
I just bought a new laptop and wanted to move my old offline messages into the new mail. I tried copying the folders into the new library/mail folder, but that just confused mail.app. So, I deleted those folders (both in finder and in mail.app) an st