fork download
  1. create table customer(customer_id int, account_id int);
  2. insert into customer values(1,10);
  3. insert into customer values(2,20);
  4.  
  5. create table contact (account_id int, time_stamp timestamp);
  6. insert into contact values(10,CURRENT_TIMESTAMP);
  7. insert into contact values(10,CURRENT_TIMESTAMP-1);
  8. insert into contact values(20,CURRENT_TIMESTAMP);
  9. insert into contact values(20,CURRENT_TIMESTAMP-1);
  10.  
  11.  
  12. SELECT Customer.customer_id, Customer.Account_ID, Contact.Account_ID, Contact.Time_stamp
  13. FROM Customer
  14. INNER JOIN Contact ON Customer.Account_ID = Contact.Account_ID
  15. WHERE Contact.Time_stamp = (SELECT MAX(C.Time_stamp) FROM Contact C WHERE C.Account_ID = Contact.Account_ID);
  16.  
Success #stdin #stdout 0s 2964KB
stdin
Standard input is empty
stdout
1|10|10|2014-06-29 02:03:34
2|20|20|2014-06-29 02:03:34