I’m trying to fetch records from a table in MySQL 5.5 (Community Server) which has 22 fields in total, the first field is of type DATETIME, and I want that field formatted with DATE_FORMAT() method, while I want to fetch remaining fields as they are. So basically what I’m trying to do is something like this
SELECT DATE_FORMAT(fdate,'%r %d-%m-%Y'),* FROM userdetails;
While I know this is invalid syntax, and currently I’m accomplishing this by selecting all the remaining fields manually which obviously makes the query longer. So is there a more elegant way to do the same? I also thought to use two different queries where 1st will fetch the formatted date and second will be usual
SELECT * FROM userdetails;
But since I fetch records sorted by date field itself, I guess using two different queries may lead to conflicts on order of records returned.
You can use
which will select all columns (including the original
fdate) along with the formatted value.There is no way to select “almost all columns” except listing them explicitly.