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
  • 59,113
  • 10
  • 31
  • 55

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,275
  • 3
  • 21
  • 29
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,336
  • 1
  • 9
  • 22