Forum Moderators: open

Message Too Old, No Replies

MySQL Where Clause Question

         

FourDegreez

2:19 am on Aug 26, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A simple question.. this is MySQL 4.x

SELECT column1, column2, column3 / 100 AS alternate_name FROM table_name WHERE alternate_name > 10;

This fails for "Unknown column 'alternate_name' in 'where clause'"

For some reason I can use alternate_name in the ORDER BY clause but not WHERE clause. What can I do to reference this column in the WHERE clause? Is it possible?

LifeinAsia

4:50 pm on Aug 26, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



You need to use:
SELECT column1, column2, column3 / 100 AS alternate_name
FROM table_name
WHERE column3 / 100 > 10

I'm not 100% positive about the logic behind this, but you can think of it as 2 different operations:
1) SELECT the data
2) ORDER the result set of data
By the time step 2 processes, "alternate_name" is defined, but "alternate_name" is not defined in the begining of step 1.