jjmusicpro Posted December 4, 2008 Share Posted December 4, 2008 I have 2 columns in a database, date, and time that looks like this column 1 column 2 1/1/09 10:32AM 1/1/09 10:35AM 1/5/09 12:32AM how can i write a query to get the latest phone call made ? i tried max but i didnt work. I wanted it to get the latest time, for each day Link to comment https://forums.phpfreaks.com/topic/135538-get-max-record/ Share on other sites More sharing options...
gevans Posted December 4, 2008 Share Posted December 4, 2008 SELECT * FROM table ORDER BY column2 DESC LIMIT 1 Link to comment https://forums.phpfreaks.com/topic/135538-get-max-record/#findComment-706075 Share on other sites More sharing options...
Mark Baker Posted December 4, 2008 Share Posted December 4, 2008 It does raise the question of why you have two columns when you could store a full date/time stamp in a single column. Are these actual date/time columns or VARCHARs? Link to comment https://forums.phpfreaks.com/topic/135538-get-max-record/#findComment-706077 Share on other sites More sharing options...
gevans Posted December 4, 2008 Share Posted December 4, 2008 my bad, update that; SELECT * FROM table ORDER BY column1, column2 DESC LIMIT 1 And yes, listen to Mark Baker Link to comment https://forums.phpfreaks.com/topic/135538-get-max-record/#findComment-706079 Share on other sites More sharing options...
jjmusicpro Posted December 4, 2008 Author Share Posted December 4, 2008 they are varchars Link to comment https://forums.phpfreaks.com/topic/135538-get-max-record/#findComment-706151 Share on other sites More sharing options...
PFMaBiSmAd Posted December 4, 2008 Share Posted December 4, 2008 That date format is not directly usable in comparisons or sorts... That time format is (assuming you always have leading zero's) because the string PM is higher in value than the string AM. The DATETIME data type exists for a reason. It requires the least amount of storage space, it is directly usable in comparisons or sorts, and it results in the fastest operating queries because you don't need to manipulate the data to just find the values you are interested in. Convert your system from using two separate varchar columns to use a single DATETIME column. Link to comment https://forums.phpfreaks.com/topic/135538-get-max-record/#findComment-706200 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.