Click here to Skip to main content
15,884,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi php experts,

Would like to ask if the query below is correct to return results sort by date? Thanks a lot.

$date_query = "select date from timesheet where ID = (select max(ID) from timesheet where status=1 and userID='".$row['ID']."') order by date desc";

What I have tried:

The code below is working but the dates are not sorted. Thanks.

$date_query = "select date from timesheet where ID = (select max(ID) from timesheet where status=1 and userID='".$row['ID']."');
Posted
Updated 6-Oct-16 22:43pm
Comments
Suvendu Shekhar Giri 7-Oct-16 2:07am    
That's what ORDER BY does. If you not apply any sorting then how DB server will be able to know what clolumn you wanted to be sort?
What's the issue with the first query?
Member 10738621 7-Oct-16 2:58am    
Hi Suvendu,

Thanks for your reply. I just want to reconfirm whether the first query is correct to sort the result by date? Thanks again.
Suvendu Shekhar Giri 7-Oct-16 3:02am    
Yes. The first one seems to be the correct one.
Member 10738621 7-Oct-16 3:04am    
So the correct one is the query with ..order by... right? Thanks.
Suvendu Shekhar Giri 7-Oct-16 3:23am    
Yes

1 solution

Adding one answer on behalf of Suvendu to close the thread.
Quote:
So the correct one is the query with ..order by... right? Thanks.
 
Share this answer
 
Comments
Suvendu Shekhar Giri 7-Oct-16 5:30am    
Thanks @Tadit :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900