Anda memerlukan alias untuk subkueri, dan Anda perlu menerapkan ketentuan untuk kedua kueri yang Anda gabungkan:
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
atau kembalikan data sehingga Anda dapat menerapkan kondisi di kueri luar:
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