954,597 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Mysql Select max date from multiple records

How can i select the latest records from a table for each invidual equipment thats due calibration within 14

Equipment_id | Date_of_last_Calibration | Calibration_Cycle | Calibration_Due_Date
test 10/02/2011 Annual 10/02/2012
test 10/02/2010 Annual 10/02/2011
test2 10/10/2011 Annual 10/10/2013
test3 08/02/2010 Annual 08/02/2011


I can select all records for calibration due within 14 days using

SELECT * FROM equipment_calibration WHERE `Calibration_Due_Date`<= ADDDATE(CURDATE(), INTERVAL 14 DAY)

but i cant limit it to display the latest records only ie

i want it to show that Equipment_id "test" that is due calibration in next 14 days but not the "test" that was last due calibration on a year ago, that was then calibrated

SHOW THIS
test 10/02/2011 Annual 10/02/2012
HIDE THIS
test 10/02/2010 Annual 10/02/2011

JukesK
Newbie Poster
15 posts since Jan 2009
Reputation Points: 10
Solved Threads: 0
 

Try

SELECT *, MAX(Calibration_Due_Date) FROM equipment_calibration WHERE `Calibration_Due_Date`<= ADDDATE(CURDATE(), INTERVAL 14 DAY)
baig772
Junior Poster
123 posts since Mar 2011
Reputation Points: 29
Solved Threads: 6
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You