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? 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 Link to comment https://forums.phpfreaks.com/topic/205915-unknown-column/#findComment-1077507 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.