• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

interpreting sql error message

 
Bob Matthews
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following code:-



and am getting the following error message............

Column reference 'xxxxxx.Field1' is invalid. When the SELECT list contains at least one aggregate then all entries must be valid aggregate expressions.

I am unsure what the error message means ?
 
Knute Snortum
Bartender
Pie
Posts: 2882
62
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
COUNT(*) is an aggregate function -- it counts the number of rows. With that function, you now need all aggregate functions for the SQL statement to make sense.
 
Bob Matthews
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes - I understand that COUNT(*) is an aggregate function

I am therefore very confused as to how to get a count of a subset of a table?
 
Knute Snortum
Bartender
Pie
Posts: 2882
62
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just don't return the fields:
 
Campbell Ritchie
Sheriff
Posts: 51341
86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moved to our databases forum.
 
Dave Tolls
Ranch Hand
Posts: 2091
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is your query trying to do?

Is it counting the rows with specific values (in which case you need a GROUP BY)?
Or is it simply counting the rows returned (in which case do as Knute says)?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic