It is inherent in your naming.
As long as your alias time is the same as the column name time, MySQL
will have no way to distinguish which one you refers to exactly in your
order-by clause, and chooses the alias in the select-clause as the one you
intended. You confused MySQL.
First, why you have
Easy.
SELECT DATE_FORMAT(`Time`, '%h:%i%p') as `Time_Format`
FROM `reservation`
ORDER BY `Time`
-Original Message-
From: BMBasal [mailto:bmb37...@gmail.com]
Sent: Wednesday, September 29, 2010 3:50 PM
To: 'Chris W'; 'MYSQL General List'
Subject: RE: ORDER BY with field alias issue
Order by reservation.time
JW
On Tuesday, September 28, 2010, Chris W 4rfv...@cox.net wrote:
I have the following query that is giving me problems.
SELECT DATE_FORMAT(`Time`, '%h:%i%p') as `Time`
FROM `reservation`
ORDER BY `Time`
Problem is it sorts wrong because of the date format