sql - selecting latest rows per distinct foreign key value -


excuse title, couldn't come short , point...

i've got table 'updates' 3 columns, text, typeid, created - text text field, typeid foreign key 'type' table , created timestamp. user entering update , select 'type' corresponds too.

there's corresponding 'type' table columns 'id' , 'name'.

i'm trying end result set many rows in 'type' table , latest value updates.text particular row in types. if i've got 3 types, 3 rows returned, 1 row each type , recent updates.text value type in question.

any ideas?

thanks,

john.

select u.text, u.typeid, u.created, t.name  (     select typeid, max(created) maxcreated     updates     group typeid ) mu inner join updates u on mu.typeid = u.typeid , mu.maxcreated = u.created left outer join type t on u.typeid = t.typeid 

Comments

Popular posts from this blog

ruby - When to use an ORM (Sequel, Datamapper, AR, etc.) vs. pure SQL for querying -

php - PHPDoc: @return void necessary? -

c++ - Convert big endian to little endian when reading from a binary file -