Hi.
I'm sure this is very simple, but my MySQL knowledge is very limited.
I got two tables: "sessions" and "users".
The important part for this in "sessions" is the column "creation_date", which is a datetime, and the "session_id".
The important part of "users" are the columns "session_id" and "last_activity" (another datetime).
I want to delete all entries from "sessions" where two clauses are true:
a) the "creation_date" is older than two days
b) in the users table, there is no user with that session_id whose "last_activity" is younger than two days.
So I guess it would be something like:
DELETE FROM sessions
WHERE TIME_TO_SEC(TIMEDIFF(NOW(), sessions.creation_date)) / 60 > 1440
AND {
SELECT COUNT(*) FROM users
WHERE TIME_TO_SEC(TIMEDIFF(NOW(), sessions.creation_date)) / 60 > 1440
AND users.session_id = sessions.session_id } > 0
Or something like that. I know it's wrong. If anyone could help me to fix it, that would be nice. Thanks.
