Let's say I have a query, and I want to store it, something like:
SET @v1 := (SELECT * FROM users);
SELECT @v1;
In some cases, this query would be super complex (a lot of joins, aggregation, etc), and sometimes I need to do the exact same query, but with an added WHERE
clause (the query would give a subset of the previous query). Something like:
SELECT * FROM users WHERE isAdmin = true
I do not want to execute the query again and I want to use the results from the previous query (so I can skip executing the long and complex query again), something like (this is not working):
SELECT * FROM @v1 WHERE isAdmin = true
How would I do that?