
December 3rd, 2011, 07:35 AM
|
 |
SQL Consultant
|
|
Join Date: Feb 2003
Location: Toronto Canada
|
|
cat_total is a column alias, and you cannot use a column alias in the WHERE clause of the same query
however, what you can do is push your entire query (marked in red below) down one level into a subquery, and then you can use the alias name in the outer query
Code:
SELECT t.*
FROM ( SELECT ibf_arcade_cats.cat_name
, ( SELECT COUNT(*)
FROM ibf_arcade_games
WHERE ibf_arcade_games.gcat = ibf_arcade_cats.c_id
) AS cat_total
FROM ibf_arcade_cats ) AS t
WHERE t.num_of_games <> t.cat_total
when you try this, you will discover yet another problem 
|