0

I'm trying to de-duplicate records by a particular field. I'm getting an error when I try a GROUP BY in my query.

An error occurred while checking the query syntax. Errors: Column 'C7226490.MyDataExt.FieldOne' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

This is the query I used:

SELECT FieldOne, FieldTwo, COUNT(FieldThree)
FROM MyDataExt
GROUP BY FieldOne

Does anyone know why I can't use this GROUP BY query? The error does go away if and only if I put every single field that I used in my SELECT into the GROUP BY. That, however, is not what I want. And I'm not certain why my COUNT() isn't being recognized as an aggregate.

  • 1
    In this query you need to add FieldTwo to the GROUP BY clause, if you are not aggregating it – Hemant Jain Nov 13 '17 at 17:33
2

What do you expect to be queried for fieldTwo? The values might be different for one result row, that's why it won't let you. Imagine the following data example :

f1| f2
a | b
a | b
a | c

If you now goup by f1 only (a), f2 will be invalid cause it is b and c at the same time. Therefore you either need to group by both or get rid of f2.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.