Link to home
Start Free TrialLog in
Avatar of area96
area96

asked on

SQL Count AS something WHERE something = value

Im getting an error  in my SQL that says that I've haven't declared a column when I already have in my count..

ERROR: Invalid column name 'counting'.

ideas and ways round the problem?
Ta!
(SELECT COUNT(schoolID) AS counting FROM Lessons WHERE register.txtSchoolID = Lessons.txtSchoolID ) AS counting
 
//then later...
 
WHERE counting > 1

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Aneesh
Aneesh
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
use the having clause instead ...

SELECT COUNT(schoolID) AS counting FROM Lessons
WHERE register.txtSchoolID = Lessons.txtSchoolID
having count(shoolid) > 1