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 Quote Link to comment 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 Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
jjmusicpro Posted December 4, 2008 Author Share Posted December 4, 2008 they are varchars Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.