I'm sure this is very basic, I'll try not to be too embarrassed asking it.
Given a table called MainTable, and a second table called Details, with a one-to-many relationship between them, which is the better practice in regards to getting a number of values from each MainTable record plus an aggregate of a value from the related Details records...?--=====================================--Method 1--Group by every selected field in MainTableSELECT MainTable.Rec_Num, MainTable.Name, MainTable.Description, SUM(Details.Amount) AS AmountFROM MainTableINNER JOIN DetailsON MainTable.Rec_Num = Details.MainTable_Rec_NumGROUP BY MainTable.Rec_Num, MainTable.Name, MainTable.Description--Method 2--Group by PK record in MainTable and aggregate the othersSELECT MainTable.Rec_Num, MAX(MainTable.Name) AS [Name], MAX(MainTable.Description) AS [Description], SUM(Details.Amount) AS [Amount]FROM MainTableINNER JOIN DetailsON MainTable.Rec_Num = Details.MainTable_Rec_NumGROUP BY MainTable.Rec_Num--=====================================
Or perhaps there's another option I'm not aware of?Thanks!Ron MosesConEst Software Systems