When I do
SELECT KPIID, KPI
FROM Country C
INNER JOIN Region R ON C.CountryID= R.CountryID
INNER JOIN Segment S ON R.SegmentID= S.SegmentID
INNER JOIN SalesRegion SR ON R.RegionID= SR.RegionID
INNER JOIN SalesPerson SP ON SR.SalesPersonID= SP.SalesPersonID
INNER JOIN SalesKPI SKPI ON SP.SalesPersonID= SKPI.SalesPersonID;
I get
KPIID | KPI |
---|---|
1 | 777009 |
1 | 777009 |
2 | 942493 |
2 | 942493 |
When I should get:
KPIID | KPI |
---|---|
1 | 777009 |
2 | 942493 |
3 | 3055026 |
4 | 6214888 |
Any fixes? Have been trying for a days and hours but cant seem to figure it out. Have gotten to this point. I need the other inner joins as I want to show the region and country names/id's, but at the moment I cant until I solve this.
I am getting duplicated rows but I dont know why.
My diagram is below, this is how my keys and relationships are laid out.
Diagram: https://i.stack.imgur.com/Cs1k0.png
CodePudding user response:
Your KPIID
and KPI
fields are in the same table SalesKPI
so your result should be:
SELECT KPIID,KPI FROM SalesKPI
Such a question, such an answer! ;-)