mysql group by last entry

Posted: April 5, 2011 in MySql, PHP

SELECT l1.leadId,l1.followUpDate,lead_status.status
 FROM lead_comment l1
 LEFT JOIN lead_comment l2 ON (l1.leadId = l2.leadId AND l1.leadCommentId < l2.leadCommentId)
 LEFT JOIN lead_status ON lead_status.statusId = l1.leadStatusId
 WHERE l2.leadCommentId IS NULL

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s