debuitls Posted August 19, 2009 Share Posted August 19, 2009 Hi, This might be an easy question for someone. I have a mysql table which has a datestamp column. I'm retrieving email records from the table using the following SELECT signuphotel.email FROM proposal LEFT JOIN signuphotel ON proposal.county = signuphotel.county AND proposal.starrating = signuphotel.starrating WHERE proposal.county = '$county' AND proposal.starrating = '$starrating'"; The problem is that this statement is retrieving all the relevant records when all I want to retrieve is the latest one. I'm thinking I need to include another AND statement saying something like AND proposal.datestamp = ….. Can anyone suggest how to retrieve just the latest record? Any help would be greatly appreciated. Thanks! Link to comment https://forums.phpfreaks.com/topic/171034-solved-retrieving-the-most-recent-record-from-a-mysql-table/ Share on other sites More sharing options...
rhodesa Posted August 19, 2009 Share Posted August 19, 2009 SELECT signuphotel.email FROM proposal LEFT JOIN signuphotel ON proposal.county = signuphotel.county AND proposal.starrating = signuphotel.starrating WHERE proposal.county = '$county' AND proposal.starrating = '$starrating' ORDER BY proposal.starrating DESC LIMIT 1 Link to comment https://forums.phpfreaks.com/topic/171034-solved-retrieving-the-most-recent-record-from-a-mysql-table/#findComment-902054 Share on other sites More sharing options...
debuitls Posted August 19, 2009 Author Share Posted August 19, 2009 Ah it obviously was an easy queston! That works fine. Thanks very much for your help rhodesa. Link to comment https://forums.phpfreaks.com/topic/171034-solved-retrieving-the-most-recent-record-from-a-mysql-table/#findComment-902055 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.