Some places allow aliases, some don't. Some (GROUP BY, ORDER BY) even allow
ordinals.
For performance, the optimal index would be
INDEX(factory_id, date)
and then do
WHERE date >= "2012-10-11"
AND date < "2012-10-11" + INTERVAL 1 DAY
> -----Original Message-----
> From: Mark Haney [mailto:[email protected]]
> Sent: Thursday, October 11, 2012 10:47 AM
> To: MySQL
> Subject: column aliases in query
>
> I know it's been a while since I wrote serious queries, but I'm sure I
> have done something like this before:
>
> SELECT SUBSTR(date,1,10) as vDate, event_id, events.mach_id,
> machine.factory_id FROM events JOIN machine ON events.mach_id =
> machine.mach_id WHERE machine.factory_id = "1" AND vDate = "2012-10-11"
>
> Where I've aliased the SUBSTR of the date and then used the alias in
> the WHERE clause of the query. I'm getting an error message now, but
> I'm almost certain I've used that syntax before. Am I missing
> something?
>
> --
>
> Mark Haney
> Software Developer/Consultant
> AB Emblem
> [email protected]
> Linux marius.homelinux.org 3.5.1-1.fc17.x86_64 GNU/Linux
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe: http://lists.mysql.com/mysql
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql