0

I would like to select last record from 1 table for each ID section connected with another table. Connection between those tables is: notes.user_id = application_forms.id and then notes.post_by_id = application_forms.user_id I would like to select last record for each notes.user_id so I can display different CSS on the fonts depending on which user enter some notes, hope it's clear, if not I am here

1st Table

CREATE TABLE notes (
  note_id int(255) NOT NULL AUTO_INCREMENT,
  note_when timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  user_id int(255) DEFAULT NULL,
  post_by_id int(255) DEFAULT NULL,
  note text,
  PRIMARY KEY (note_id)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1;

2nd Table

CREATE TABLE application_forms (
  id int(255) NOT NULL AUTO_INCREMENT,
  user_id int(255) DEFAULT NULL,
  PRIMARY KEY (id)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1;
user974435
  • 377
  • 2
  • 13
  • 31
  • 3
    What query have you tried so far? – kgautron Sep 03 '12 at 13:05
  • SELECT application_forms.online_offline, application_forms.online_offline2, application_forms.property_full_address, application_forms.submission_status, application_forms.employers_reference, application_forms.landlord_reference, application_forms.comp_by_app, application_forms.notes, application_forms.decision, application_forms.id, n.post_by_id FROM application_forms LEFT JOIN (SELECT user_id , MAX(note_id) , notes.post_by_id FROM notes) as n ON n.user_id = application_forms.id – user974435 Sep 03 '12 at 13:07
  • it's just doesnt work :( – user974435 Sep 03 '12 at 13:07
  • can you post some example rows of both tables and of the result table? – golimar Sep 03 '12 at 13:35
  • there is table for notes and table for "applications" - each application can have unlimited notes, now I am trying to display different CSS for Notes Text to know which user wrote last note – user974435 Sep 03 '12 at 13:42
  • http://stackoverflow.com/questions/1313120/retrieving-the-last-record-in-each-group – user974435 Sep 03 '12 at 13:54

0 Answers0