MySQL Every derived table must have its own alias

MySQL requires that all derived tables and subqueries have an alias. You are missing an alias at the end of the closing parentheses for the subqquery:

SELECT * 
FROM students as st
INNER JOIN 
(
  SELECT  att.roll_no,att.full_name, 
    SUM(att.hasAttended= 'P') AS DaysPresent, 
    SUM(att.hasAttended= 'A') AS DaysAbsent, 
    COUNT(*) AS totalClasses
  FROM     attendance as att
  GROUP BY att.roll_no
) att  ---------------------------< this is missing
  ON st.roll_no = att.roll_no
WHERE st.class = 1 
ORDER BY  st.roll_no

Leave a Comment