I'm working on a timesheet tracking application - each time a person's hours are changed, a new row gets added to the database. The columns are timeid (int primary key), employmentid (int), hours (decimal 4,2) and payperiodid (int).
For each employment, I want to query the most recent hours for each payperiod.
This query seems like it should do what I want - and in all the tutorials / examples I've read, it does.
But when *I* run it, it returns a table of data: a column of max(timeid)s which correspond to their respective payperiodids. But the hours are NOT correct - this column is being queried without being tied to the max(timeid) result.
A coworker suggested I run a query inside a query, but this is way too inefficient for my needs, and seems unnecessary.
Why isnt my query working properly!!!!!?? ???
For each employment, I want to query the most recent hours for each payperiod.
Code:
SELECT hours,ppid,max(timeid) FROM hours WHERE employmentid=%d GROUP BY ppid
But when *I* run it, it returns a table of data: a column of max(timeid)s which correspond to their respective payperiodids. But the hours are NOT correct - this column is being queried without being tied to the max(timeid) result.
A coworker suggested I run a query inside a query, but this is way too inefficient for my needs, and seems unnecessary.
Why isnt my query working properly!!!!!?? ???
Comment