Jump to content
Existing user? Sign In
Sign In
Remember me
Not recommended on shared computers
Sign In
Forgot your password?
Sign Up
W3Schools.com
Browse
Forums
Events
Guidelines
Staff
Online Users
Leaderboard
More
Activity
All Activity
Search
More
Leaderboard
More
More
Everywhere
Status Updates
Topics
Events
Members
Home
All Activity
Home
VJS
VJS
Members
View Profile
See their activity
Posts
2
Joined
June 9, 2020
Last visited
June 10, 2020
Content Type
All Activity
Profiles
Status Updates
Status Replies
Forums
Topics
Posts
Events
Events
Event Comments
Everything posted by VJS
HELP with JOIN
VJS
posted a topic in
SQL
I am joining 2 tables using the query below. Its many to many relationship. The join works fine but creates multiple rows for each item which is expected but the Amount/value column is also duplicated. How to avoid this? Thanks As you can see the Current output the value (50000 appears 3 times instead of 1 and 27000 appears 3 times instead of 1) SELECT * FROM T1 INNER JOIN T2 ON T1.Projectex = T2.WBS_Parent Table 1: +-----------+------------+-----------+----------+--------+----------+-------+ | Projectex | CAPEX_OPEX | costelmnt | sap_vers | Period | FISCYEAR | VALUE | +-----------+------------+-----------+----------+--------+----------+-------+ | 0-01081 | CAPEX | 3416 | 61 | 3 | 2020 | 50000 | | 0-01081 | OPEX | 7077 | 30 | 5 | 2020 | 27000 | +-----------+------------+-----------+----------+--------+----------+-------+ Table2: +------------+-----------------+---------+---------+ | WBS_PARENT | FINANCILAL_YEAR | MEASURE | AMOUNT | +------------+-----------------+---------+---------+ | 0-01081 | 2020 | CPX | 2000000 | | 0-01081 | 2020 | OPX | 50000 | | 0-01081 | 2020 | OPX | 1000000 | +------------+-----------------+---------+---------+ CURRENT OUTPUT: Projectex| CAPEX_OPEX| costelmnt| sap_vers| Period| FISCYEAR| VALUE| 0 0-01081| CAPEX| 3416| 61| 3| 2020| 50000| 1 0-01081| CAPEX| 3416| 61| 3| 2020| 50000| 2 0-01081| CAPEX| 3416| 61| 3| 2020| 50000| 3 0-01081| OPEX| 7077| 30| 5| 2020| 27000| 4 0-01081| OPEX| 7077| 30| 5| 2020| 27000| 5 0-01081| OPEX| 7077| 30| 5| 2020| 27000| WBS_PARENT FINANCILAL_YEAR MEASURE AMOUNT 0 0-01081| 2020| CPX| 2000000 1 0-01081| 2020| OPX| 50000 2 0-01081| 2020| OPX| 1000000 3 0-01081| 2020| CPX| 2000000 4 0-01081| 2020| OPX| 50000 5 0-01081| 2020| OPX| 1000000 Expected Output: Projectex| CAPEX_OPEX| costelmnt| sap_vers| Period| FISCYEAR| VALUE| 0 0-01081| CAPEX| 3416| 61| 3| 2020| 50000| 1 0-01081| CAPEX| 3416| 61| 3| 2020| 2 0-01081| CAPEX| 3416| 61| 3| 2020| 3 0-01081| OPEX| 7077| 30| 5| 2020| 27000| 4 0-01081| OPEX| 7077| 30| 5| 2020| 5 0-01081| OPEX| 7077| 30| 5| 2020| WBS_PARENT FINANCILAL_YEAR MEASURE AMOUNT 0 0-01081| 2020| CPX| 2000000 1 0-01081| 2020| OPX| 50000 2 0-01081| 2020| OPX| 1000000 3 0-01081| 2020| CPX| 4 0-01081| 2020| OPX| 5 0-01081| 2020| OPX|
June 9, 2020
1 reply
sql
join
(and 2 more)
Tagged with:
sql
join
merge
union
Aahi
VJS
posted a topic in
General
Hi, Need help with SQL JOIN Currently I have the below SELECT * FROM T1 INNER JOIN T2 ON T1.Projectex = T2.WBS_Parent I need the join withut duplicating the sum values as highlighted in the JOIN table in the attached pic.
June 9, 2020
1 reply
All Activity
Home
VJS
×
Existing user? Sign In
Sign Up
W3Schools.com
Browse
Back
Forums
Events
Guidelines
Staff
Online Users
Leaderboard
Activity
Back
All Activity
Search
Leaderboard
×
Create New...