MySQL Subquery - Every derived table must have an alias
I'd appreciate some help here, I've got this query that works in the MySQL Workbench against my MySQL Database:
... but when run on the web page with PHP gives the error:
SELECT COUNT(DetentionID) AS CountOfDetentions, UPN, Forename, Surname FROM tbldetentions WHERE UPN IN (SELECT classUPN FROM tblclasses WHERE classClass LIKE '%11R2') GROUP BY UPN
I'm struggling with this, as I've tried putting AS in various places but still getting the same error.
Couldn't execute query. Every derived table must have its own alias - SELECT count(*) as c FROM (SELECT 1 as c FROM tblclasses WHERE classClass LIKE '%11R2') GROUP BY UPN) o
Essentially this SQL statement is counting up the number times a UPN number appears in a table but the subquery is only selecting the UPN Numbers to check that are matched to a particular class number.