I have a table in Mysql (firstname,lastname,data1,data2,...) that one field name is MYDATE and type of this field is timestamp
. In this field, the date saved as (yyyy-mm-dd mm:ss:ms), and there are many records of this table.
I want write a select query that sort this table with (yyyy-mm-dd) and without considering (mm:ss:ms).
ORDER BY date(mydate)
but it will cause fullscan.
Just cast it to a date in your order by clause:
SELECT columns
FROM some_table
ORDER BY CAST(mydate AS date);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With