dweb Posted March 23, 2013 Share Posted March 23, 2013 Hi I have the following query; SELECT m.name,m.gender,m.dob, (SELECT FLOOR( DATEDIFF( 'date('Y-m-d')',m.dob ) / 365.25 )) AS age FROM members m which gets David Male 1990-08-17 22John Male 1978-02-15 35 and that all works ok what i want to do, is extend the query to grab rows when the member is between a set age but when i do WHERE age BETWEEN 30 AND 40 i get Unknown column 'age' in 'where clause' any idea why? thanks Link to comment https://forums.phpfreaks.com/topic/276051-selecting-rows-with-a-certain-age/ Share on other sites More sharing options...
mac_gyver Posted March 23, 2013 Share Posted March 23, 2013 this is a chicken and egg age problem. the age value is calculated in the select term for the rows that have been selected. the where term determines which rows to select. the easiest, not fastest, way would be to use a HAVING age BETWEEN 30 AND 40 term. the fastest way would be to put the calculation into the WHERE term. Link to comment https://forums.phpfreaks.com/topic/276051-selecting-rows-with-a-certain-age/#findComment-1420517 Share on other sites More sharing options...
dweb Posted March 23, 2013 Author Share Posted March 23, 2013 thank you, works great Link to comment https://forums.phpfreaks.com/topic/276051-selecting-rows-with-a-certain-age/#findComment-1420518 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.