I am currently making a program that will send an email if the date of a persons last entry was over (some time frame). my table is laid out like this:
employee | dept. | date | other |
bob | 1 | 2012-05-29 | abc |
bob | 1 | 2012-07-15 | xyz |
jon | 2 | 2012-05-29 | abc |
(i have sorted with mysql by employee then date)
so for example, for bob i want to automatically assign a variable to the date 2012-07-15 because that is the date of his last entry. then based on the current date i want to send an email if that time in between submissions has been to long. My question is how to i assign a variable to the last date of each person in the table? I am also open to different better ways of doing this. Thank you.
To return the latest date for each employee, something like this will work.
Addendum,
As simbabque points out, this works for getting the latest date, but does not return the
othervalue. There are a couple of approaches to getting that result set.If we are guaranteed that the (employee,date) is UNIQUE (for example. by a unique constraint), we can return other columns on the row that has the latest date with a query like this:
If we aren’t guaranteed that (employee, date) is unique, this query would not suffice. But there are a couple of approaches to addressing that issue.