0

I am running this query on MySQL and it is giving this error:

Every derived table must have its own alias.

SELECT MAX (mycount) FROM 
(SELECT CreatedBy,COUNT(CreatedBy) mycount 
FROM audit_csp_evaluation 
GROUP BY CreatedBy);
Barbaros Özhan
  • 47,993
  • 9
  • 26
  • 51

2 Answers2

1

You have to name the derived table, like this:

SELECT MAX(x.mycount) AS max_mycount
FROM 
(
 SELECT CreatedBy
    , COUNT(CreatedBy) AS mycount 
FROM audit_csp_evaluation 
GROUP BY CreatedBy
) x;

x is the name I'm giving the derived table.

kjmerf
  • 4,125
  • 2
  • 18
  • 28
0

You need to give a name to the table derived from your subquery.

SELECT MAX(c.mycount) FROM 
(
 SELECT CreatedBy,COUNT(CreatedBy) mycount 
 FROM audit_csp_evaluation 
 GROUP BY CreatedBy
 )c <---added name here;
isaace
  • 3,273
  • 1
  • 9
  • 19