What i am trying to achieve is that i want result set returned in two groups for two username with latest data
SELECT TOP(100) id , insertdate, modifieddate, detail, username FROM MyTable
WHERE username = 'AAA' or username='1234'
GROUP BY username
ORDER BY insertdate DESC
But when i run this query i get error :
Column 'MyTable.id' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
How do i achieve this?

Abhishek Sharma52 reputationPosted Jun 19, 2017, 10:22 AM EDT
Nepethya RanaRank #4,361 · 348 reputationPosted Jun 19, 2017, 10:31 AM EDT
Abhishek Sharma52 reputationPosted Jun 19, 2017, 10:53 AM EDT
GROUP BYreturns a single row for each unique combination of theGROUP BYfields. So in your example, every distinct combination of"username"occurring in rows of"MyTable"results in a row in the query representing the group of rows with the given combination of group by field values.