Du skal bruge et alias for underforespørgslen, og du skal anvende betingelserne enten på begge forespørgsler, som du forener:
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
eller returner data, så du kan anvende betingelsen i den ydre forespørgsel:
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