php - How to list most recently updated parent upper in the query? -
i have pic related parent/child tables. every 1 row in parent table, there can 100 or 200 child rows in child table. when upgrade child table; give it's parent row's tid number child's row under thread id column. so, there isn't more 1 parent row each child row.
if had column in parent table "lastchildtimestamp" upgrade related row last child timestamp? if can show me example?
what want achieve keep updated parents upper when list out parents , want make easy. if have better solution or method i'm open too.
there 2 different approaches use solve problem.
- create parent.lastchildtimestamp field, use database trigger update it.
see: http://www.techonthenet.com/mysql/triggers/after_update.php
in particular, set after insert , after update triggers in child table update associated parent row.
- alternately, instead aggregate data child rows when need read it. query looks like:
select max(timestamp) child child.threadid = (thread id)
Comments
Post a Comment