Potřebujete alias pro poddotaz a musíte použít podmínky buď na oba sjednocované dotazy:
SELECT MAX(DateTime)
FROM (
SELECT DateTime
FROM Class_Searches
WHERE User_Email = '[email protected]'
AND DateTime > NOW( ) - INTERVAL 30 DAY
UNION ALL
SELECT DateTime
FROM Book_Searches
WHERE User_Email = '[email protected]'
AND DateTime > NOW( ) - INTERVAL 30 DAY
) AS x
nebo vrátit data, abyste mohli použít podmínku ve vnějším dotazu:
SELECT MAX(DateTime)
FROM (
SELECT DateTime, User_Email
FROM Class_Searches
UNION ALL
SELECT DateTime, User_Email
FROM Book_Searches
) AS x
WHERE User_Email = '[email protected]'
AND DateTime > NOW( ) - INTERVAL 30 DAY