mysql - Get last modified values for each records from two tables joins? -
i have 2 tables accounts
, calls
. account
table contain account details , call
table contain call details date_modified
, others account id in parent_id
column.
there lots of records , need query fetch accounts last call details (most recent call).
i have tried not able result.
select accounts.id, accounts.name, calls.name subject accounts inner join calls on accounts.id = calls.parent_id accounts.id=( select c.parent_id calls c c.parent_id = calls.parent_id order c.date_modified desc limit 1 )
try query: should work.
select * accounts inner join ( select c.parent_id ,c.name ,c.date_modified calls c inner join ( select parent_id ,max(date_modified) call_date calls group parent_id ) cc on cc.parent_id = c.parent_id , cc.call_date = c.date_modified ) ccc on ccc.parent_id = a.id
Comments
Post a Comment