I would like to know if it's possible to find a value in a select statement and use it in a where clause like:
SELECT col1, MAX(col2) - COUNT(DISTINCT col3) as variable
FROM table
WHERE col1 > variable
"table" is pretty big, and I want to narrow down the records the query has to look at as quickly as possible.
I know this isn't bit of code isn't possible as written (#1054 - Unknown column 'variable' in 'where clause'), but is there anyway to figure out the value of "variable" and then use it in the WHERE clause?