php - MYSQL selecting all records with the most recent date -


i have database stores history of transactions, comment updates. therefore, accept multiple records same id.

what need pull in of records , display recent of each record.

here example of 2 records same uid. highlighted record recent of 2.

2 rows database

here 1 of queries attempted:

 select     uid    ,voyage    ,max(comments)    ,max(edituser)    ,max(editdate)      table  group    uid  order    uid 

here same uid returned:

result database

if you'll notice, recent user , editdate, it's not recent comment, should 'this test comment'.

i have tried several queries, closest i've gotten returning recent of every record.

i tried link: sql select record recent date

but don't think need use joins in case, being in same table. again, strength not in mysql.

i'm hoping can me providing correct (and better) query make work.

with this, better off using sub-selects.

select      t1.uid,     t1.voyage,     (select comments table t2 t2.uid = t1.uid , t2.editdate = max(t1.editdate) limit 1) comments,     (select edituser table t2 t2.uid = t1.uid , t2.editdate = max(t1.editdate) limit 1) edituser,     (select editdate table t2 t2.uid = t1.uid , t2.editdate = max(t1.editdate) limit 1) editdate, table t1 group t1.uid order t1.uid 

each sub-select narrows down same uid, , takes 1 recent editdate.


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -