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

unicode - Are email addresses allowed to contain non-alphanumeric characters? -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

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