I'm trying optimizing a query, trying to avoid repeating the query indicated with "COMPLEX QUERY", that is used 2 times and both, has the same results.
The original query
SELECT news.*
FROM news
INNER JOIN((SELECT myposter
FROM (SELECT **COMPLEX QUERY**))
UNION
(SELECT myposter
FROM `profiles_old` prof2
WHERE prof2.profile_id NOT IN (SELECT **COMPLEX QUERY**))) r
ON news.profile = r.p
I was wondering if something like this was possible:
SELECT news.*
FROM (SELECT **COMPLEX QUERY**) complexQuery,
news
INNER JOIN ((SELECT myposter
FROM complexquery)
UNION
(SELECT myposter
FROM `profiles_old` prof2
WHERE prof2. profile NOT IN (SELECT myposter
FROM complexQuery))) r
ON news. profile = r.p
Does Mysql do some sort of caching of that type of query?