mb81 Posted April 15, 2008 Share Posted April 15, 2008 Here is my query: SELECT COUNT(*) AS countreservations,reserveddate,resourceid FROM RESERVATIONS_reservedresources GROUP BY reserveddate,resourceid ORDER BY countreservations DESC I want to get a set of results back where only where countreservations>1 is returned. If I try to insert WHERE countreservations>1, it says it doesn't know that column If I try to insert WHERE COUNT(*)>1, it says illegal use of group function Is there any way to get just the records that have 2 for the COUNT(*)? Thanks. Link to comment https://forums.phpfreaks.com/topic/101240-solved-conditions-based-upon-count-field/ Share on other sites More sharing options...
gluck Posted April 15, 2008 Share Posted April 15, 2008 Use having clause Link to comment https://forums.phpfreaks.com/topic/101240-solved-conditions-based-upon-count-field/#findComment-517879 Share on other sites More sharing options...
gluck Posted April 15, 2008 Share Posted April 15, 2008 SELECT COUNT(*) AS countreservations,reserveddate,resourceid FROM RESERVATIONS_reservedresources GROUP BY reserveddate,resourceid having count(countreservations) > 1 Link to comment https://forums.phpfreaks.com/topic/101240-solved-conditions-based-upon-count-field/#findComment-517880 Share on other sites More sharing options...
mwasif Posted April 15, 2008 Share Posted April 15, 2008 SELECT COUNT(*) AS countreservations,reserveddate,resourceid FROM RESERVATIONS_reservedresources GROUP BY reserveddate,resourceid HAVING countreservations>1 ORDER BY countreservations DESC Link to comment https://forums.phpfreaks.com/topic/101240-solved-conditions-based-upon-count-field/#findComment-517894 Share on other sites More sharing options...
gluck Posted April 15, 2008 Share Posted April 15, 2008 mwasif is correct .. I meant to type count(*) Link to comment https://forums.phpfreaks.com/topic/101240-solved-conditions-based-upon-count-field/#findComment-517899 Share on other sites More sharing options...
mb81 Posted April 15, 2008 Author Share Posted April 15, 2008 Cool, never had to use that before, thanks for the info, I knew there was something I was missing. Thanks! SOLVED Link to comment https://forums.phpfreaks.com/topic/101240-solved-conditions-based-upon-count-field/#findComment-517921 Share on other sites More sharing options...
mwasif Posted April 15, 2008 Share Posted April 15, 2008 You are welcome. Link to comment https://forums.phpfreaks.com/topic/101240-solved-conditions-based-upon-count-field/#findComment-517933 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.