Mark Tabor

Mark Tabor

  • 569
  • 1.9k
  • 431.2k

How to include other columns in nested Select statement with

Jun 15 2016 3:05 AM
I have a select statement and in that i have a nested select statement , and in nested select statement i have aggregate function on one column , I want to add more columns with this nested select statement , and i just want to group by on one column ,
check the below query
SELECT t1.DynamicIndicatorID,t1.District,t1.Quarter,t1.District,t1.TFA,t1.TFB,t1.TFG,t1.TFW,t1.TFM,x.fileID as fileID,x.filenameName as FileName
FROM DynamicIndicatorsTargetsForPu t1
LEFT JOIN (
SELECT IndicatorID,filenameName, MAX(fileID) AS fileid
FROM tblUploadedFiledetailsForPartners group by IndicatorID
) x ON t1.DynamicIndicatorID = x.IndicatorID where t1.UserId=59
I am getting an error
Msg 8120, Level 16, State 1, Line 4
Column 'tblUploadedFiledetailsForPartners.filenameName' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
I want to add more columns in Nested select statement as i have to show these columns as well but i want to group by on just one column . 

Answers (6)