Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to refer to a calculated column?

Status
Not open for further replies.

BPetro

Programmer
Joined
Oct 1, 2002
Messages
59
Location
US
I thought this would be it, but it isn't - can anyone share how to refer to the calculated column "age" in the where clause -- here's the sample code -- mySql is giving the error that "age" is not a column...

Thanks!

mysql> select id,
period_diff(to_days(curdate()),to_days(entryDate)) as age
from prayerList where age < 10;
ERROR 1064: You have an error in your SQL syntax near 'where age < 10' at line 1
 
My bad - actually the mySql error is:
ERROR 1054: Unknown column 'age' in 'where clause'
I copied the wrong line in my first version.
 
You have to repeat the expression in the where clause.
 
You can use an alias in ORDER and HAVING but not WHERE. See the MySQL Appendix &quot;Problems with aliases&quot;.

 
Thanks guys - that's what I needed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top