MySQL : Sort by Date and Time together when there are in different columns

Suppose you have date and time in two different columns of your table.
We can sort date and time together by using the ADDTIME function.
 select * from mytable ORDER BY ADDTIME(mydate, mytime);  

You can also use the ADDTIME in the select clause to get data and time together.
 select ADDTIME(mydate, mytime), city from mytable  

No comments:

Post a Comment

Python contextlib for Timing Python code

If you've ever found yourself needing to measure the execution time of specific portions of your Python code, the `contextlib` module o...