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. Quote Link to comment Share on other sites More sharing options...
gluck Posted April 15, 2008 Share Posted April 15, 2008 Use having clause Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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(*) Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
mwasif Posted April 15, 2008 Share Posted April 15, 2008 You are welcome. Quote Link to comment 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.