Skip to content
Advertisement

MySQL Count as {name} and WHERE {name} = X, Unknown column

I am trying to filter results based on the name assigned on count() and get this:

After more research I did find out about not being able to use a column alias in the WHERE but I am unsure how to execute this query then. I assume it’s possible but how would I be able to filter the results based on the count() calculation of the query?

Advertisement

Answer

total_submissions is a column alias and the result of an aggregation function. You need to do that check in a havingclause:

Notes:

  • Table aliases make the query easier to write and to read.
  • The condition on doc_id should still be in the WHERE clause.
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement