When I try to select couple of columns with count, I get the following error:
Selected non-aggregate values must be part of the associated group
My query is something like this.
SELECT COUNT(1), COLUMN1, COLUMN2 FROM TABLE-NAME
Advertisement
Answer
If you’re after a count for each combination of COLUMN1 and COLUMN2:
SELECT COUNT(1), COLUMN1, COLUMN2 FROM TABLE_NAME GROUP BY COLUMN1, COLUMN2
If you’re after a count of all records in the table:
SELECT COUNT(1) OVER (), COLUMN1, COLUMN2 FROM TABLE_NAME