Answer the question
In order to leave comments, you need to log in
Why doesn't this select work?
Hello everyone!
Tell me why this select does not work?
SELECT field1, count(field1), field2
FROM [Table]
group by field1
having count(field1)>1
order by count(field1) desc
Answer the question
In order to leave comments, you need to log in
What a strange request you have. try this:
SELECT field1, count(field1) as countf1, field2
FROM [Table]
group by field1, field2
having countf1>1
order by field1 desc
Since you did not provide the text of the error, I will vangue.
Field2 is not included in either GROUP BY or aggregate function. This means that there is an ambiguous choice, from which row, which has fallen into the group, to take this field.
According to the ANSI SQL standard, this use of the field is prohibited.
SELECT field1, COUNT( field1 ), STRING_AGG( field2, ',' )
FROM [Table]
GROUP BY field1
HAVING COUNT( field1 ) > 1
ORDER BY COUNT( field1 ) DESC
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question