I am trying to find a better way to do this. I have a subquery getting a "total" in the select clause but I want that returned value used in the main queries where like
SELECT , (SELECT COUNT() FROM tableA) AS total
FROM tableB
WHERE total > 5
This of course gives me an error says total doesn't exist. I can get this to work by doing this
SELECT , (SELECT COUNT() FROM tableA) AS total
FROM tableB
WHERE (SELECT COUNT(*) FROM tableA) > 5
You are probably asking why not just remove it from the select, well this query is used to list data from the database and "total" is a value I want to get, only if someone uses a filter and tells me that they need total to be a certain value do I need to limit the results on total so the subquery in the select is always there. The subquery results are not always used in the condition (the "where" conditions are automatically added or removed based on user filters), so is there a way to do this without having to run two subquires when they want to limit the results on the subquery total?
Thanks,
Danny