Let assume we have 2 tables:
table name: hids
hid | status |
---|---|
001 | 2 |
002 | 1 |
003 | 1 |
004 | 2 |
005 | 2 |
... unique on hid
and: table name: times
hid | uid | time |
---|---|---|
001 | 00001 | 12345 |
001 | 00001 | 12567 |
001 | 00002 | 12540 |
001 | 00003 | 12541 |
001 | 00003 | 12567 |
002 | 00001 | 12575 |
... (no uniques)
The problem is: For a given user (eg. uid=00001) UPDATE status in "hids" with 0 if:
- current status is 2
- in the "times" table there isn't any record for any other user with time > (time of the latest entry for uid=00001 and the same hid)
Currently I do it with PHP is a way which is not too effecitve (thousends of atom queries). As the database grows over time (even for several milion records) the code is ineffective due to PHP overhead. Is there any option to make it simpler?