I have this query that I will create into a stored procedure after this query is complete.I have commented a line of code within this query. This line of code will insert the data that the query creates (Pretty much a grouped query of @Data). I need to take this query and JOIN the table that I need to INSERT the data into. I want the JOIN to eliminate the possibility of displaying duplicates.How should this query look?Thanks for your help!!Declare @Data Table (RowId Integer Identity(1,1), tRSSQL_TRANS DateTime, bEND_OF_REEL bit, nLINE Integer )Insert Into @Data(tRSSQL_TRANS, bEND_OF_REEL, nLINE)Select tRSSQL_TRANS, bEND_OF_REEL, nLINE From vM_FR_STOPS_GroupingOrder By nLine, tRSSQL_TRANS--Insert Into tM_FR_WIP_UnitID_FastStops(nLINE, StartGroup, EndGroup)Select A.nLine, A.StartGroup, Min(D.tRSSQL_TRANS) As EndGroupFrom ( Select B.tRSSQL_TRANS As StartGroup, B.nLine From @Data A Inner Join @Data B On A.RowId = B.RowId -1 And A.nLine = B.nLine Where A.bEND_OF_REEL = 1 And B.bEND_OF_REEL = 0 ) A Inner Join @Data D On A.nLine = D.nLine And A.StartGroup < D.tRSSQL_TRANS And D.bEND_OF_REEL = 1Group By A.StartGroup, A.nLine