Getting no result by joining three tables in BMM
Hi all,
I have a requirement where I have a fact table and two ailas dimension table.
Let say fact is w_account_f and dimension ailas dim_w_account_d_trans and dim_w_account_d_sal of w_account_d table
I have join in physical layer
w_account_f ----> dim_w_account_d_trans with forgin key join
w_account_f ----> dim_w_account_d_sal with forgin key join
In BMM i have join these three table but given content level filter in dimension like
dim_w_account_d_trans.tans_col = 'active'
dim_w_account_d_sal.sal > 4000
when i am trying to pull the report from all three table
w_account_f, dim_w_account_d_trans, dim_w_account_d_sal
its not giving any result where as when i trying to pull report with fact any one dimension its giving me result.
can anyone help me in finding the soulting how to get the data by joining all these three tables.
Hi,
Take the physical query with all three tables selected. Run the query in sql developer, remove the joins one by one and check where it fails. Modify the rpd model accordingly.
Regards,
Dpka
Similar Messages
-
I have to join three tables but i m getting error as given below:
Error i m getting-
Syntax error(missing operator) in query expression 'invoice.INVOICE_NO=inv_ent_main.INVOICE_NO INNER JOIN invrate ON invrate.INVOICE_NO=inv_ent_main.INVOICE_N'.
My Query is-
"select inv_ent_main.EXPORTER,inv_ent_main.INVOICE_NO,inv_ent_main.INVOICE_DATE,inv_ent_main.BALE_COUNT,inv_ent_main.TOTAL_AMOUNT,inv_ent_main.BALE_COUNT,inv_ent_main.TOTAL_PIECES,inv_ent_main.TOTAL_AREA,invoice.ORDER_NO,invoice.OTHER_REF,invoice.CONSIGN1,invoice.CONSIGN2,invoice.CONSIGN3,invoice.CONSIGN4,invoice.CONSIGN5,invoice.DLV_TERMS,invoice.PAYMENT_TERMS,invoice.PRE_CARRIAGE,invoice.PR_CARRIER,invoice.DESTINATION,invoice.COUNTRY_DESTINATION,invoice.VESS_FLIGHT,invoice.PORT_LOAD,invoice.PORT_DSCH,invoice.MARK1,invoice.MARK2,invoice.CURRENCY,invoice.GOODS_DESCRIPTION,invoice.CFB,invoice.GROSS_WEIGHT,invoice.NET_WEIGHT,invoice.WOOL,invoice.COTTON
from inv_ent_main INNER JOIN invoice ON invoice.INVOICE_NO = inv_ent_main.INVOICE_NO INNER JOIN invrate ON invrate.INVOICE_NO = inv_ent_main.INVOICE_NO";
MCA,LUCKNOW.The last character in the error message has missing "O" when compare to the actual query you have posted. Please rerun it an verify or you can try the below query. You need to post DDL for all the 3 tables so that we can test.
select
inv_ent_main.EXPORTER,
inv_ent_main.INVOICE_NO,
inv_ent_main.INVOICE_DATE,
inv_ent_main.BALE_COUNT,
inv_ent_main.TOTAL_AMOUNT,
inv_ent_main.BALE_COUNT,
inv_ent_main.TOTAL_PIECES,
inv_ent_main.TOTAL_AREA,
invoice.ORDER_NO,
invoice.OTHER_REF,
invoice.CONSIGN1,
invoice.CONSIGN2,
invoice.CONSIGN3,
invoice.CONSIGN4,
invoice.CONSIGN5,
invoice.DLV_TERMS,
invoice.PAYMENT_TERMS,
invoice.PRE_CARRIAGE,
invoice.PR_CARRIER,
invoice.DESTINATION,
invoice.COUNTRY_DESTINATION,
invoice.VESS_FLIGHT,
invoice.PORT_LOAD,
invoice.PORT_DSCH,
invoice.MARK1,
invoice.MARK2,
invoice.CURRENCY,
invoice.GOODS_DESCRIPTION,
invoice.CFB,
invoice.GROSS_WEIGHT,
invoice.NET_WEIGHT,
invoice.WOOL,
invoice.COTTON from inv_ent_main
INNER JOIN invoice ON invoice.INVOICE_NO = inv_ent_main.INVOICE_NO
INNER JOIN invrate ON invrate.INVOICE_NO = inv_ent_main.INVOICE_NO
Regards, RSingh -
How can i get all the records from three tables(not common records)
Hi
I have four base tables at R/3-Side. And i need to extract them from R/3-Side.
And i dont have any standard extractor for these tables .
If i create a 'View' on top of these tables. Then it will give only commom records among the three tables.
But i want all the records from three base tables (not only common).
So how can i get the all records from three tables. please let me know
kumarYou can create separate 3 datasources for three tables and extract data to BW. There you can implement business login to build relation between this data.
-
Code to Join three tables.
Hi All,
I am a fresher to this ABAP.
I have an task to join three tables which doesn't take much effort. But the problem is: the tables have same columns, (name, age and city) in all the three tables.
The layout is as shown below:
Table 1 ( T1 ) Table 2 ( T2 ) Table 3 ( T3 )
name | age | city name | age | city name | age | city -
Anju 21 HDD Anju 20 BGH Anju 21 SFF
Julie 23 JUH Julie 24 JUH Julie 20 JUH
Now, there should be a selection screen. If I enter a value for this varaible as "Anju", The output should be like:
Col T1 T2 T3
Name Anju Anju Anju
Age 21 20 21
City HDD BGH SFF
I am unable to appraoch how to solve this issue. Any pointers would be of great help.
Thanks in advance,
Anjum.
Edited by: nasarat anjum on Apr 23, 2008 8:43 AMHi,
U can take three internal tables for each of ur tables T1,T2,T3. Fetch the respective table data into ur internal tables.
Then write,
loop at itab1.
read table itba2 with key name eq itab1-name.
read table itab3 with key name eq itab1-name.
write : / name under <name heading>,
itab1-name under <T1 heading>,
itab2-name under <T2 heading>,
itab3-name under <T3 heading>.
write : / age under <age heading>,
itab1-age under <T1 heading>,
itab2-age under <T2 heading>,
itab3-age under <T3 heading>.
write : / city under <city heading>,
itab1-city under <T1 heading>,
itab2-city under <T2 heading>,
itab3-city under <T3 heading>.
<removed by moderator>
Thanks
Edited by: Mike Pokraka on Aug 6, 2008 8:30 AM -
How to join three tables?
I have used this query to join three tables but it displays an error : field vbak-vbeln is unknown.
please help me out..
SELECT vbak-vbeln vbak-bstnk vbap-matnr vbap-zmeng makt-maktx
INTO CORRESPONDING FIELDs OF TABLE itab FROM vbak
inner JOIN vbap ON vbak-vbeln eq vbap-vbeln
inner JOIN makt ON vbap-matnr eq makt-matnr
WHERE vbak-bstnk = s_bstnk.Hi mohan kumar ,
just follow the Syntax
SELECT FLD1 FLD2 FLD3 FLD4 FLD5 INTO CORRESPONDING FIELDS OF TABLE ITAB FROM TABLE1 INNER JOIN TABLE2 ON
TABLE1FLD1 = TABLE2FLD1 INNER JOIN TABLE3 ON TABLE2FLD2 = TABLE3FLD2 INNER JOIN TABL4 ON TABLE3FLD3 = TABLE4FLD3
WHERE FLD1 = 'AA'
Hope this may be helpful.
Please reward points if found ok.
Thanks and regards,
Rajeshwar. -
Joining three tables to get totals on three columns.
hi gurus,
i have spent hours and hours to get the desired result with this join query. 98% of the query bring results according to my expectations but for some reasons few results are duplicating. let me give you the structure of my tables than my query and than what i expect it to bring. here we go;
There are three tables
*1. SENDER*
Name Null? Type
SNAME VARCHAR2(50)
SPHONE1 NOT NULL VARCHAR2(15)
SPHONE2 VARCHAR2(15)
SPHONE3 VARCHAR2(15)
SCITY VARCHAR2(25)
SREMARKS VARCHAR2(200)
IDENTIFICATION VARCHAR2(20)
ADD1 VARCHAR2(30)
ADD2 VARCHAR2(30)
*2. TRANSACTION*
Name Null? Type
T_ID NOT NULL NUMBER
SPHONE1 VARCHAR2(15)
R_ID NUMBER
RB_ID VARCHAR2(10)
TRANSFER_TO VARCHAR2(25)
TDATE DATE
SOURCE VARCHAR2(20)
CURR VARCHAR2(10)
PAID VARCHAR2(10)
MOP VARCHAR2(10)
DOLLAR NUMBER
RATE NUMBER(5,2)
RUPPEE NUMBER
TREM1 VARCHAR2(200)
TREM2 VARCHAR2(100)
PPAYMENT VARCHAR2(10)
PROMISE VARCHAR2(50)
BALANCE NUMBER
DOLLAR2 NUMBER
*3. PAYMENTS*
Name Null? Type
PAYMENT_ID NOT NULL NUMBER
PDATE DATE
SPHONE1 VARCHAR2(15)
AMT_PAID NUMBER
BALANCE NUMBER
T_ID NUMBER
QUERY_
select a.sname, a.sphone1, nvl(sum(b.dollar),0) ORD, nvl(sum(b.dollar2),0) ADV,
nvl(sum(c.amt_paid),0) Paid
from sender a, transaction b, payments c
where a.sphone1 = b.sphone1
and b.t_id = c.t_id(+)
and b.paid in ('N','B')
group by a.sname, a.sphone1
order by 1
HERE IS THE RESULT OF THIS QUERY:_
SNAME SPHONE1 ORD ADV PAID
Muhammad Atif Ishtiaq 778 889 7195 2150 635 45
BRIEF DESCRIPTION:*
We have sender info in SENDER table, when they place order it goes to TRANSACTION table and when they pay it goes into PAYMENTS. some times they make payments in installment of a single order. which i record them in payments with their T_ID (Transaction ID) and this is the problem what i research until now. many customers place multiple orders over a period of time but dont pay and some times pay the orders in installment. i just want to present the whole story in one single row, as i mentioned above under query result. in this example the actual ORD suppose to be $2050 instead and ADV $605. PAID is OK.
SQL> select t_id, dollar, dollar2 from transaction where paid = 'B' and sphone1 = '778 889 7195';
T_ID DOLLAR DOLLAR2
18274 450
18278 1000 500
18263 100 30
18265 100
18266 100
18268 100 25
18269 200 50
SQL> select t_id, amt_paid from payments
where t_id in (select t_id from transaction
where paid = 'B' and sphone1 = '778 889 7195')
T_ID AMT_PAID
18263 20
18263 25
AND in the end i would like to calculate balance of the columns ((ORD+ADV) - (PAID))
Any help would be appreciated.
best regards.
NOTE: i am running oracle 8 and developer 6itry this:
WITH TRANSACTION AS (select 18274 t_id, 450 dollar, NULL dollar2, '778 889 7195' sphone1 FROM DUAL
UNION ALL
select 18278 t_id, 1000 dollar, 500 dollar2, '778 889 7195' sphone1 FROM DUAL
UNION ALL
select 18263 t_id, 100 dollar, 30 dollar2, '778 889 7195' sphone1 FROM DUAL
UNION ALL
select 18265 t_id, 100 dollar, NULL dollar2, '778 889 7195' sphone1 FROM DUAL
UNION ALL
select 18266 t_id, 100 dollar, NULL dollar2, '778 889 7195' sphone1 FROM DUAL
UNION ALL
select 18268 t_id, 100 dollar, 25 dollar2, '778 889 7195' sphone1 FROM DUAL
UNION ALL
select 18269 t_id, 200 dollar, 50 dollar2, '778 889 7195' sphone1 FROM DUAL
PAYMENTS AS (select 18263 t_id, 20 amt_paid FROM DUAL
UNION ALL
select 18263 t_id, 25 amt_paid FROM DUAL
SENDER AS (SELECT 'Muhammad Atif Ishtiaq' SNAME, '778 889 7195' SPHONE1 FROM DUAL
select a.sname,
a.sphone1,
nvl(ORD,0) ORD,
nvl(ADV,0) ADV,
nvl(amt_paid,0) Paid
from sender a,
(SELECT sphone1,
sum(dollar) ord,
sum(dollar2) adv
from transaction b
GROUP BY sphone1) b,
(SELECT sphone1,
SUM(amt_paid) amt_paid
FROM payments p,
transaction t
where p.t_id=t.t_id
GROUP BY sphone1) c
where a.sphone1 = b.sphone1
and b.sphone1=c.sphone1(+); -
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] -
How to join three tables and practical difference between 10g and 11g
I want to know with example how to outer join three different tables in Oracle.
Also if you have any website or reference for understand syntax or performance difference between 10g and 11g then please paste a link in.thanks!!Hi,
897293 wrote:
I want to know with example how to outer join three different tables in Oracle.The 3rd table comes into the result set the same way the 2nd one did:
FROM table_1 t1
LEFT OUTER JOIN table_2 t2 ON ...
LEFT OUTER JOIN table_3 t3 ON ...The join condition(s) for t3 can reference t1, or t2, or both.
Also if you have any website or reference for understand syntax or performance difference between 10g and 11g then please paste a link in.thanks!!The main manuals all have "What's New" sections near the beginning. For example:
http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/wnsql.htm#sthref5
Hoek,
We've missed you. Welcome back! -
Joining Three Tables with multiple record
Dear All
we need some help. We have Three Tables in sqlserver2012
Master Table
OrderID PackageID CustomerName
1 1 Abc
2 2 Bcd
3 1 xyz
Child1 Table
OrderID ControlName
1 Row1COlumn1 (It Means Pant in Red Color is selected by user(relation with Child2 Table))
1 Row3Column1 (It Means Gown in Blue Color is selected by user(relation with Child2 Table))
1 Row4Column3 (It Means T Shirt in White Color is selected by user(relation with Child2 Table))
2 Row1Column2 (It Means Tie in Green Color is selected by user(relation with Child2 Table))
2 Row3Column1 (It Means Bow in Red Color is selected by user(relation with Child2 Table))
Child2 Table
PackageID Product Color1 Color2 Color3
1 Pant Red Green Blue
1 Shirt Blue Pink Purple
1 Gown Blue Black Yellow
1 T Shirt Red Green White
2 Tie Red Green White
2 Socks Red Green White
2 Bow Red Green White
We want to have result like
OrderID PackageID CustomerName Pant Gown T Shirt Tie Bow
1 1 ABC Red Blue White x
x
Blue
2 2 Bcd x x x
Green Red
I have tried
;with mycte as (
select ms.OrderID,ms.PackageID
,ms.CustomerName
, Replace(stuff([ControlName], charindex('Column',ControlName),len(ControlName),''),'Row','') rowNum
,Replace(stuff([ControlName], 1, charindex('Column',ControlName)-1 ,''),'Column','') columnNum
From child1 c inner join MasterTable ms on c.Orderid=ms.orderid)
,mycte1 as (
select *, row_number() Over(Partition By PackageID Order By Child2ID) rn from child2
,mycte2 as (
Select m.OrderID,m.PackageID, m.CustomerName, m.ColumnNum, m1.Product
--,m1.Color1 , m1.Color2, m1.Color3
, Case WHEN ColumnNum= 1 Then Color1
WHEN ColumnNum= 1 Then Color1
WHEN ColumnNum= 2 Then Color2
WHEN ColumnNum= 3 Then Color3 End Colors
from mycte m
join mycte1 m1 on m.rowNum=m1.rn and m.PackageID=m1.PackageID)
Select OrderID,PackageID,CustomerName, ISNULL(Max(Case WHen Product='Pant' Then Colors END),'X') as 'Pant'
, ISNULL(Max(Case WHen Product='Gown' Then Colors END),'X') as 'Gown'
, ISNULL(Max(Case WHen Product='T Shirt' Then Colors END),'X') as 'T Shirt'
, ISNULL(Max(Case WHen Product='Tie' Then Colors END),'X') as 'Tie'
, ISNULL(Max(Case WHen Product='Bow' Then Colors END),'X') as 'Bow'
FROM mycte2
Group by OrderID,PackageID, CustomerName
it works if we have a product in one color only. like if we have pant in red and blue then its showing just first record
Thanks and Best Regards UmairAre you really storing textual values like "Row3Column1" or "Row4Column3"???
Your model is a mess. Redesign it.. btw, these kind of models are quite complex.
USE tempdb;
GO
CREATE TABLE dbo.Colors
ColorID INT NOT NULL ,
ColorName NVARCHAR(255) NOT NULL ,
CONSTRAINT PK_Colors PRIMARY KEY ( ColorID )
CREATE TABLE dbo.Products
ProductID INT NOT NULL ,
ProductName NVARCHAR(255) NOT NULL ,
CONSTRAINT PK_Products PRIMARY KEY ( ProductID ) ,
CONSTRAINT UQ_Products_ProductName UNIQUE ( ProductName )
CREATE TABLE dbo.Packages
PackageID INT NOT NULL ,
CONSTRAINT PK_Packages PRIMARY KEY ( PackageID )
CREATE TABLE dbo.PackageDetails
ColorID INT NOT NULL ,
PackageID INT NOT NULL ,
ProductID INT NOT NULL ,
CONSTRAINT PK_PackageDetails PRIMARY KEY ( ColorID, PackageID, ProductID ) ,
CONSTRAINT FK_PackageDetails_ColorID FOREIGN KEY ( ColorID ) REFERENCES dbo.Colors ( ColorID ) ,
CONSTRAINT FK_PackageDetails_PackageID FOREIGN KEY ( PackageID ) REFERENCES dbo.Packages ( PackageID ) ,
CONSTRAINT FK_PackageDetails_ProductID FOREIGN KEY ( ProductID ) REFERENCES dbo.Products ( ProductID )
CREATE TABLE dbo.Orders
OrderID INT NOT NULL ,
CustomerID INT NOT NULL ,
PackageID INT NOT NULL ,
CONSTRAINT PK_Orders PRIMARY KEY ( OrderID ) ,
CONSTRAINT UQ_Orders_CustomerID UNIQUE ( OrderID, PackageID ) ,
CONSTRAINT FK_Orders_PackageID FOREIGN KEY ( PackageID ) REFERENCES dbo.Packages ( PackageID )
CREATE TABLE dbo.OrderDetails
ColorID INT NOT NULL ,
OrderID INT NOT NULL ,
PackageID INT NOT NULL ,
ProductID INT NOT NULL ,
CONSTRAINT FK_OrderDetails_Orders FOREIGN KEY ( OrderID, PackageID ) REFERENCES dbo.Orders ( OrderID, PackageID ) ,
CONSTRAINT FK_OrderDetails_PackageDetails FOREIGN KEY ( ColorID, PackageID, ProductID ) REFERENCES dbo.PackageDetails ( ColorID, PackageID, ProductID )
GO
INSERT INTO dbo.Colors
( ColorID, ColorName )
VALUES ( 1, 'Red' ),
( 2, 'Green' ),
( 3, 'Blue' ),
( 4, 'Pink' ),
( 5, 'Purple' ),
( 6, 'Black' ),
( 7, 'Yellow' ),
( 8, 'White' );
INSERT INTO dbo.Products
( ProductID, ProductName )
VALUES ( 1, 'Pant' ) ,
( 2, 'Shirt' ) ,
( 3, 'Gown' ) ,
( 4, 'T Shirt' ) ,
( 5, 'Tie' ) ,
( 6, 'Socks' ) ,
( 7, 'Bow' );
INSERT INTO dbo.Packages
( PackageID )
VALUES ( 1 ),
( 2 );
INSERT INTO dbo.PackageDetails
( PackageID, ProductID, ColorID )
VALUES ( 1, 1, 1 ),
( 1, 2, 3 ),
( 1, 3, 3 ),
( 1, 4, 1 ),
( 2, 5, 1 ),
( 2, 6, 1 ),
( 2, 7, 1 ),
( 1, 1, 2 ),
( 1, 2, 4 ),
( 1, 3, 6 ),
( 1, 4, 2 ),
( 2, 5, 2 ),
( 2, 6, 2 ),
( 2, 7, 2 ),
( 1, 1, 3 ),
( 1, 2, 5 ),
( 1, 3, 7 ),
( 1, 4, 8 ),
( 2, 5, 8 ),
( 2, 6, 8 ),
( 2, 7, 8 );
INSERT INTO dbo.Orders
( OrderID, PackageID, CustomerID )
VALUES ( 1, 1, 1 ),
( 2, 2, 2 ),
( 3, 1, 3 );
INSERT INTO dbo.OrderDetails
( ColorID, OrderID, PackageID, ProductID )
VALUES ( 1, 1, 1, 1 ),
( 3, 1, 1, 3 ),
( 8, 1, 1, 4 ),
( 2, 2, 2, 5 ),
( 1, 2, 2, 7 );
GO
SELECT *
FROM dbo.Orders O
INNER JOIN dbo.OrderDetails OD ON OD.OrderID = O.OrderID
INNER JOIN dbo.Products P ON P.ProductID = OD.ProductID
INNER JOIN dbo.Colors C ON C.ColorID = OD.ColorID;
GO
DROP TABLE dbo.OrderDetails;
DROP TABLE dbo.Orders;
DROP TABLE dbo.PackageDetails;
DROP TABLE dbo.Packages;
DROP TABLE dbo.Products;
DROP TABLE dbo.Colors;
GO -
Need help with the update queries - joining three tables -
We have three tables shown below, each with millions of rows;
And need some updates in here;
T_CHECK->TOTAL_AMT_PAID should be equal to
aim00.t_chck_clm_xref->amt_paid + aim01.t_chck_clm_xref->amt_paid;
Some CHECK_SAK values exist in aim00.t_chck_clm_xref and some exist in aim01.t_chck_clm_xref;
We tried to update using the queries within PL/SQL shown below:
Is there a way to make these more effecient?
SQL> desc aim.t_check;
Name Null? Type
CHECK_SAK NOT NULL NUMBER(9)
TOTAL_AMT_PAID NOT NULL NUMBER(11,2)
DTE_ISSUE NOT NULL NUMBER(8)
SQL> desc aim00.t_chck_clm_xref
Name Null? Type
CHECK_SAK NOT NULL NUMBER(9)
AMT_PAID NOT NULL NUMBER(10,2)
SQL> desc aim01.t_chck_clm_xref
Name Null? Type
CHECK_SAK NOT NULL NUMBER(9)
AMT_PAID NOT NULL NUMBER(10,2)
create or replace PROCEDURE CHECKSUPDATE IS
cursor my_cursor is
select /*+ DRIVING_SITE(t_check) INDEX(t_check) */
tot, mid, aim.t_check.total_amt_paid from
(select sum(aim01.t_chck_clm_xref.amt_paid) tot,
aim01.t_chck_clm_xref.check_sak mid from aim01.t_chck_clm_xref
where
not exists (select 'x' from aim00.t_chck_clm_xref
where aim01.t_chck_clm_xref.check_sak = aim00.t_chck_clm_xref.check_sak
group by aim01.t_chck_clm_xref.check_sak) TABLE1, aim.t_check
where aim.t_check.check_sak = table1.mid
and aim.t_check.total_amt_paid <> tot;
my_count NUMBER;
BEGIN
my_count:=0;
for my_pos in my_cursor loop
update aim.t_check a set total_amt_paid=my_pos.tot
where a.check_sak=my_pos.mid;
my_count:=my_count+1;
if (mod(my_count,1000)=0) THEN
commit;
end if;
end loop;
commit;
END CHECKSUPDATE;>
SQL> desc t_check;
Name Null? Type
CHECK_SAK NUMBER(9)
TOTAL_AMT_PAID NUMBER(11,2)
DTE_ISSUE NUMBER(8)
SQL> desc t_chck_clm_xref
Name Null? Type
CHECK_SAK NUMBER(9)
AMT_PAID NUMBER(10,2)
SQL> desc t_test
Name Null? Type
CHECK_SAK NUMBER(9)
AMT_PAID NUMBER(10,2)
select check_sak, sum(amt_paid)
from (
select check_sak, amt_paid from t_chck_clm_xref
union all
select check_sak, amt_paid from t_test
group by check_sak;and use this query in an UPDATE statement or a MERGE statement, as Tubby suggested, against the T_CHECK table.
isotope -
Joining three tables to get specific data set
table1
id
seq
dat
table2
id
seq
empid
taxid
Table3
empid
taxid
I want to find out records That have same id,seq,empid having different taxid column Common to three of the tables .
Please help meHi,
There are a lot of different things you could mean.
Here's how to do one of them:
SELECT t2.id, t2.seq, t2.empid
FROM table2 t2
JOIN table1 t1 ON t2.id = t1.id
AND t2.seq = t1.seq
JOIN table3 t3 ON t2.emp_id = t3.empid
AND t2.taxid = t3.taxid
GROUP BY t2.id, t2.seq, t2.empid
HAVING COUNT (DISTINCT t2.taxid) > 1
;It would help if you posted some sample data (CREATE TABLE and INSERT statements) from all 3 tables, and the results you want from that data. -
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 -
Get desired data from joining multiple tables
I have the following query which is returning some data.
SELECT i.IssueId, i.IssueDesc, i.MainRecId, a.PlantId
FROM Issues i INNER JOIN PlantPcontact pp ON i.SubmitterId = pp.PContactId
INNER JOIN Plant a ON a.PlantId = pp.PlantId
WHERE (a.PlantStatus = 1)
ORDER BY i.IssueId
I need to join i.MainRecId and a.PlantId from the results of this query with another table PlantDoc (pd) ON PDMainRecId and PDPlantId respectively (one-to-one relationship) and retrieve additional information (pd.PlantDocId).
How do I accomplish everything in one single query ?
I am looking for the following data finally.
i.IssueId, i.IssueDesc, i.MainRecId, a.PlantId, pd.PlantDocIdExample for JOINs with many tables:
http://www.sqlusa.com/bestpractices/fourtablejoin/
Kalman Toth Database & OLAP Architect
SQL Server 2014 Database Design
New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012 -
Joining three tables through link tables
I have three separate tables that are related to each other through two link tables.
Employees have a many to many relationship with Programs (1 link table)
Employee + Programs have a many to many relationship with Attributes (The employee attributes depend on the program). This is another link table.
So, the first link table (emp_prog_lk) has two columns, employee_id and program_id. The second link table has three attributes, employee_id, program_id, and attribute_id.
The question is, how can I map the Employee object so that I can call getAttributes(Program) and receive the list of attributes for the specified program? Is this even possible without writing custom SQL?
Thanks.How do you want your object model to look? Do you want Employee to simply have a Collection of Attributes? If so, then you're right, I don't think this is possible -- but to me if you'd like this association table between employees and Attributes to have extra info (in this case a Program), then you need to consider and model it in your Object model.
I.e., when you have a relationship table that has anything other than the PK's of the 2 tables it's relating, then you really need to model that in Java and aren't really able to rely on the java.util.Collection to suffice.
- Don
Maybe you are looking for
-
What are the difference in transaction codes in 4.6 C and ECC 6.0 HCM syste
Hi What are the difference in transaction codes in 4.6 C and ECC 6.0 in HCM SAP. Regards, Sanjay
-
Preview doesn't display images to fit window
I'm running OSX 10.6.8 on a 27" iMac, and when I enlarge the Preview window to fit the screen (by dragging the corner), the images don't enlarge. They seem to be stuck at about 1920 pixels wide (at a guess) instead of 2560 wide. I can zoom in, but I
-
From R/3 we are sending our Salary Info IDOC to our EXTERNal Payroll dept. In R/3 We are running a job and that will produce 250 IDOCS and this has to be collected in the Receiver File System. Should I need to use a BPM for the above scenario? Or on
-
Standby database not working after reinstallation of oracle in primary DB
Hello All, Initially I had setup primary database (DB1) and Standby database (DB2), for test environment. In DB1 I had got ORA-600 error. So, after I researched, I came to know that I need to apply some patches. But I reinstalled oracle in DB1. And t
-
What's the best cover for the new iPad (3rd generation). I've been told by a store employee (university bookstore) that there are problems with the magnetic covers on the newest iPad. Suggestions?