Im trying to JOIN together various datasets to get a master table, though I managed to preserve the row count after 3 left joins, but after the next step, it seems to increase it. Any ideas why?
Query with 3 Joins
-------------------------------------------------------------------
--- STEP 4: ----------------
-------------------------------------------------------------------
SELECT
DISTINCT Table1.[Field1]
, Table1.[Field2]
, Table3.[Field3]
, Table1.[Field4]
, Table1.[Field5]
, Table1.[Field6]
, Table1.[Field7]
, Table1.[Field8]
, Table1.[Field9]
, Table1.[Field10]
FROM db1.dbo.raw_tbl_1 AS Table1
LEFT JOIN db2.dbo.tbl_2 Table2
ON Table1.Field7 = Table2.[Field13]
LEFT JOIN db2.dbo.tbl_3 Table3
ON CONVERT(INT,Table1.[Field2]) = Table3.Field14
LEFT JOIN db2.dbo.tbl_4Table4
ON Table2.Field17= Table4. Field15
WHERE Table2. Field17 IS NOT NULL
-- 2682270 rows (Desired row count)
Query with 4 Joins (The one that increases row count)
-------------------------------------------------------------------
--- STEP 5: ----
-------------------------------------------------------------------
SELECT
DISTINCT Table1.[Field1]
, Table1.[Field2]
, Table3.[Field3]
, Table1.[Field4]
, Table1.[Field5]
, Table1.[Field6]
, Table1.[Field7]
, Table5.[Field11]
, Table6.[Field12]
, Table1.[Field8]
, Table1.[Field9]
, Table1.[Field10]
FROM db1.dbo.raw_tbl_1 AS Table1
LEFT JOIN db2.dbo.tbl_2 Table2
ON Table1.Field7 = Table2.[Field13]
LEFT JOIN db2.dbo.tbl_3 Table3
ON CONVERT(INT,Table1.[Field2]) = Table3. Field14
LEFT JOIN db2.dbo.tbl_4 Table4
ON Table2. Field17= Table4. Field15
LEFT JOIN db2.dbo.tbl_5 Table5
ON Table4. Field18= Table5. Field16
LEFT JOIN db2.dbo.tbl_6 Table6
ON Table5.[Field11] = CONVERT(INT,Table6.[Table6])
WHERE Table2.Field17 IS NOT NULL