Group By Question
Group By Question
(OP)
Will this Group By statement work with ANSI SQL:
SELECT max(last_updated_dt) as max_dt, field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11, field12, field13, field14, field15
INTO #temp_table
FROM myTable
GROUP BY field1, field2, field3
HAVING last_updated_dt = max(last_updated_dt)
Or do I need to put all the fields except for the date field in the group by?
Thanks,
SELECT max(last_updated_dt) as max_dt, field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11, field12, field13, field14, field15
INTO #temp_table
FROM myTable
GROUP BY field1, field2, field3
HAVING last_updated_dt = max(last_updated_dt)
Or do I need to put all the fields except for the date field in the group by?
Thanks,
RE: Group By Question
If a GROUP BY clause is specified, each column reference in the SELECT list must either identify a grouping column or be the argument of a set function.
I.e. list all columns except last_updated_dt in the GROUP BY clause.