Jump to content

[SOLVED] Retrieving the most recent record from a mysql table


debuitls

Recommended Posts

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!

 

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.