The Little Guy Posted June 26, 2010 Share Posted June 26, 2010 SELECT *, a.answer as ans,COUNT(*) as total FROM phrases p LEFT JOIN answers a ON(p.id = a.phrase) WHERE p.id = 1 AND total > 1 GROUP BY a.answer ORDER BY total DESC With the above I am getting an error saying: Unknown column 'total' in 'where clause' This column is created, it holds a count, how can I only get results where the count (a.k.a. total) is larger than 1? Quote Link to comment https://forums.phpfreaks.com/topic/205915-unknown-column/ Share on other sites More sharing options...
The Little Guy Posted June 26, 2010 Author Share Posted June 26, 2010 got it. Had to use a HAVING clause: SELECT *, a.answer as ans, COUNT(a.answer) as total FROM phrases p LEFT JOIN answers a ON(p.id = a.phrase) WHERE p.id = 1 GROUP BY a.answer HAVING total > 1 ORDER BY total DESC Quote Link to comment https://forums.phpfreaks.com/topic/205915-unknown-column/#findComment-1077507 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.