Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
05-23-2014, 10:27 AM #1
- Join Date
- Jun 2011
- Thanked 0 Times in 0 Posts
Multiple ORDER BY trying to sort by follow up date.
Hello and thanks in advance,
I have a database table containing contact logs for our booking system, I want to be able to list all the logs and filter them firstly by Status and then order those by their follow up date
I have tried a variety of the following but whilst is sorts by Status the dates seem to be in a random order. I've used -STR because some do not have dates and I want those to be put at the bottom of the order, and STR_TO_DATE becuase I'm using UK dates and a varchar field.
sql = "SELECT * FROM contact_log ORDER BY CL_Status, -STR_TO_DATE(CL_FU_Date, '%d/%m/%Y') DESC"
05-23-2014, 03:44 PM #2
- Join Date
- May 2005
- Southern tip of Silicon Valley
- Thanked 218 Times in 211 Posts
Is that a typo in your post or did you actually prepend a dash to the function call?
Instead of using * to select all fields, you should be explicit and specify each field you need and in the order you want them returned.
This is untested, but give it a try. (Don't forget to add the additional fields you need)
$sql = "SELECT CL_Status, STR_TO_DATE(CL_FU_Date, '%d/%m/%Y') AS CL_FU_Date FROM contact_log ORDER BY CL_Status ASC, CL_FU_Date DESC";