rhughessa Posted March 27, 2011 Share Posted March 27, 2011 So here's the query I'm trying which is returning a "error in your syntax" error SELECT COUNT(restaurant_id) AS number, category, lat, lon, ( 3959 * acos( cos( radians(41.044128) ) * cos( radians( lat ) ) * cos( radians( lon ) - radians(-81.524117) ) + sin( radians(41.044128) ) * sin( radians( lat ) ) ) ) AS distance FROM restaurants HAVING distance < 25 GROUP BY category ORDER BY category This is an attempt at combining the following 2 queries that both work independently. 1. SELECT COUNT(restaurant_id) AS number FROM restaurants GROUP BY category ORDER BY category 2. SELECT lat, lon, ( 3959 * acos( cos( radians(41.044128) ) * cos( radians( lat ) ) * cos( radians( lon ) - radians(-81.524117) ) + sin( radians(41.044128) ) * sin( radians( lat ) ) ) ) AS distance FROM restaurants HAVING distance < 25 Thanks in advance, Robert Quote Link to comment https://forums.phpfreaks.com/topic/231900-need-help-with-complicated-query/ Share on other sites More sharing options...
blacknight Posted March 30, 2011 Share Posted March 30, 2011 what is the full syntax error? Quote Link to comment https://forums.phpfreaks.com/topic/231900-need-help-with-complicated-query/#findComment-1194022 Share on other sites More sharing options...
ngreenwood6 Posted March 30, 2011 Share Posted March 30, 2011 Well that seems to be a cool query and all but I see one flaw with it. When you have a COUNT() in the query it only returns one row. So you are not going to get more than one result with that query. Quote Link to comment https://forums.phpfreaks.com/topic/231900-need-help-with-complicated-query/#findComment-1194028 Share on other sites More sharing options...
kickstart Posted March 30, 2011 Share Posted March 30, 2011 Hi The problem is that you have the HAVING clause in the wrong place. If should be after the GROUP BY. However you shouldn't have non aggregate columns in the SELECT clause which are not in the GROUP BY clause. MySQL is pretty tolerant of this, but some flavours of SQL will reject it out of hand. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/231900-need-help-with-complicated-query/#findComment-1194240 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.