trying to put a condition in the main where clause that checks a value from a subquery.
SELECT total, (select my_count from x where .. etc) as XXX
FROM sales
WHERE XXX > 0;
I get an unknown column error. Any ideas why?
What about
select total, xxx
from (
SELECT total, (select my_count from x where .. etc) as XXX
FROM sales
)
WHERE XXX > 0;
This is a really strange query.
Why don't you put the WHERE condition inside the subquery?
SELECT total, (select my_count from x where .. AND my_count > 0) as XXX
FROM sales
And you're getting an error because you can't use the result of a subquery as a column name.