If I have a query, such as:
select column1, (
select count(*) from table2
) as some_count
from table1
where column1 = 'foo'
I can use column1
in the where clause, but if I try to add
and some_count > 0
then I get an error that some_count
doesn't exist. How can I use that in a where clause?
Use HAVING
select column1, (
select count(*) from table2
) as some_count
from table1
HAVING some_count > 0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With