My situation is I have two tables. I want to join them together and have duplicate records appear on the same line. Mock table structures given below
MainTbl Cols: MKey1,MKey2,MData1,MData2,MData3
SuppTbl Cols: SPrimaryKey,SKey1,SKey2,SData1,SData2
I want to LEFT JOIN MainTbl to SuppTbl. However, SuppTbl contains duplicates of SKey1 and SKey2 combo key.
The results I want are below, Where "-#" indicates the duplication number.
MKey1,MKey2,MData1,MData2,MData3,SData1-1,SData2-1,SData1-2,SData2-2
In essence, all fields from the join should be contain on one row based one Key1 and Key2.
ATTEMPTED ANSWER BY SEAN W
SELECT
MainTbl.MKey1,
MainTbl.MKey2,
tcd.SData1 AS SData11,
tcd.SData2 AS SData22,
tcr.SData1 AS SData12,
tcr.SData2 AS SData22
FROM MainTbl
LEFT JOIN SuppTbl tcd
ON MainTbl.MKey1=tcd.SKey1 AND MainTbl.MKey2=tcd.SKey2
LEFT JOIN SuppTbl tcr
ON MainTbl.MKey1=tcr.SKey1 AND MainTbl.MKey2=tcr.SKey2
WHERE tcd.SData1 < tcr.SData1
RESULT No Success. Did not pull any records.