I currently have an SQL query that is taking a LONG time to load, wondered if anyone could help me? I'm fairly new with MySQL.
This is the query:
SELECT applicationid
FROM logs
WHERE action = 'VIEWED'
AND userid = '$user'
AND date >= '$dateminus7'
AND applicationid NOT IN (
SELECT applicationid
FROM logs
WHERE userid = '$user'
AND date >= '$dateminus7'
AND (action LIKE 'SUBMITTED NOTE%' OR action LIKE 'CHANGED STATUS%')
)
Basically looking through some databases to find users that are not leaving notes when they access customer accounts (very naughty). There are around 30,000 records per week in the logs database, which is obviously a factor, but right now the query runs for an hour and still doesn't complete (times out, 404 error on PHP page).
Any info needed just ask, I'd appreciate any tips or pointers.
EDIT: EXPLAIN results https://i.sstatic.net/xYhPt.png
EXPLAINstatement.EXPLAIN SELECT applicationid ...displays how the SQL engine will process the query, particularly which indexes will be used.