Column is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause I'm trying to get the last time the data was modified in the tables of the database without any duplicating object_ids ,as I was getting 4 of the same object_Ids because the last_user_update field is present four times for the same object_id .I have tried different variations by grouping with Object_id ,max(Object_Id) and different fields and I still get the same error .
What is the right way to do this ?
This is the error message I'm getting

Column 'sys.dm_db_index_usage_stats.user_scans' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

    select  max(i.object_id)
                ,S.name
                ,I.last_user_scan
                ,i.user_scans
                ,i.user_lookups
            ,i.last_user_update
                ,i.last_system_scan
                ,i.user_updates 
                ,s.modify_date
    from sys.dm_db_index_usage_stats I
    Inner Join sys.objects S
    ON I.object_id = S.object_id
    WHERE type = 'U'

group by S.name
You're getting the same object_id multiple times because you get a row per index, not a row per object. The point of this DMV is to show you which indexes are getting used more or less than others. So maybe you want:

select  I.object_id
            ,S.name
            ,si.name
            ,I.last_user_scan
            ,i.user_scans
            ,i.user_lookups
            ,i.last_user_update
            ,i.last_system_scan
            ,i.user_updates 
            ,s.modify_date
from sys.dm_db_index_usage_stats I
Inner Join sys.objects S
ON I.object_id = S.object_id
INNER JOIN sys.indexes AS si
ON I.[object_id] = si.[object_id]
AND I.index_id = si.index_id
WHERE type = 'U';


If you really just want the last access and the sum of all activity against a table, without caring about which index(es):

SELECT s.name 
            ,MAX(I.last_user_scan)
            ,SUM(i.user_scans)
            ,SUM(i.user_lookups)
            ,MAX(i.last_user_update)
            ,MAX(i.last_system_scan)
            ,SUM(i.user_updates) 
            ,MAX(s.modify_date)
from sys.dm_db_index_usage_stats I
Inner Join sys.objects S
ON I.object_id = S.object_id
WHERE type = 'U'
group by S.name; 


These aren't ideal because if you have dbo.Accounts and test.Accounts, they will get grouped together.