I’m having trouble with a SQL query, I can’t think how to phrase it.
It’s to pull a count of events from a log since you last checked it.
Currently I have this:
SELECT COUNT(*) AS alertcount, date AS alertdate
FROM alerts WHERE to_id = '$id' AND date > '$lastcheck'
But, I want it to exclude all fields where expire=1 and the date is over 30 mins old.
So if both of them expressions are true, it will ignore that record in the count.
I dont know your DB engine but if is SQL Server, use the
dateaddfunction to calculate thegetdate() -30 minutesexpressionEDIT:
here is the condition with your new comment. not sure where the to_id will fit in this scenario and also you dont need a date parameter