20

Possible Duplicate:
every derived table must have its own alias

I need to find maximum of actions per user

table columns: action_id, action_status, user

request:

SELECT MAX(`counted`) FROM
(
SELECT COUNT(*) AS `counted`
FROM `table_actions`
WHERE `status` = "good"
GROUP BY `user`
)

error message: "Every derived table must have its own alias"

what is wrong?..

Community
  • 1
  • 1
Zdomb
  • 205
  • 1
  • 2
  • 6

1 Answers1

26

That just means MySQL insists that you give the inner SELECT a name, like:

SELECT MAX(counted) FROM
(
    SELECT COUNT(*) AS counted
    FROM table_actions
    WHERE status = "good"
    GROUP BY user
) AS counts;
potashin
  • 44,205
  • 11
  • 83
  • 107
Michael Slade
  • 13,802
  • 2
  • 39
  • 44
  • omg... such small change... thx! – Zdomb Apr 28 '12 at 12:39
  • 2
    if you also select the row status, it won't be accurate: `select max(counted), status from (select count(*) as counted, status ...` won't work... the field "status" won't be accurate. I don't really know how to fix this – pr00thmatic Nov 30 '15 at 01:34