mga_ka_php Posted January 10, 2009 Share Posted January 10, 2009 How do you correct this statement SELECT a.siteID 'ID', a.siteDomain 'Site', COUNT(*) 'New Members' FROM sites a LEFT JOIN users b ON a.siteID=b.siteID WHERE b.userDateRegistered>='1231513284' AND b.userDateRegistered<='1231553482' GROUP BY a.siteID have 2 tables, sites and users, i want to view all the sites with how many members the problem with this code it only display the sites with >0 users i want to show even the 0 users Site | New Members site.com | 0 site2.com | 10 Link to comment https://forums.phpfreaks.com/topic/140249-solved-cannot-show-all-rows/ Share on other sites More sharing options...
Gamic Posted January 10, 2009 Share Posted January 10, 2009 SELECT a.siteID 'ID', a.siteDomain 'Site', COUNT(b.*) 'New Members' FROM sites a LEFT OUTER JOIN users b ON a.siteID=b.siteID WHERE (b.userDateRegistered between '1231513284' and '1231553482') or b.userDateRegistered is null GROUP BY a.siteID Link to comment https://forums.phpfreaks.com/topic/140249-solved-cannot-show-all-rows/#findComment-733927 Share on other sites More sharing options...
mga_ka_php Posted January 14, 2009 Author Share Posted January 14, 2009 still doesn't work. if i remove the WHERE result would be Site | New Members site.com | 50 site2.com | 10 site3.com | 25 result is good, it gets the total number of new members, all time but if i add the WHERE, it will not show all the sites, it will only show the sites with new members Site | New Members site.com | 50 site3.com | 25 Link to comment https://forums.phpfreaks.com/topic/140249-solved-cannot-show-all-rows/#findComment-736714 Share on other sites More sharing options...
mga_ka_php Posted January 14, 2009 Author Share Posted January 14, 2009 thinking about this sql statement SELECT a.siteDomain 'Site' FROM sites a WHERE ( SELECT COUNT(b.userID) FROM users b WHERE b.userDateRegistered between '1231513284' and '1231553482' ) can i move the COUNT(b.userID) to SELECT a.siteDomain 'Site'? Link to comment https://forums.phpfreaks.com/topic/140249-solved-cannot-show-all-rows/#findComment-736720 Share on other sites More sharing options...
fenway Posted January 14, 2009 Share Posted January 14, 2009 I don't understand what's wrong anymore. Link to comment https://forums.phpfreaks.com/topic/140249-solved-cannot-show-all-rows/#findComment-736883 Share on other sites More sharing options...
mga_ka_php Posted January 15, 2009 Author Share Posted January 15, 2009 figured it out.thanks. what i did was SELECT siteDomain 'Site', ( SELECT COUNT(userID) FROM users WHERE (userDateRegistered BETWEEN '1231733663' AND '1231910698') AND users.siteID=sites.siteID ) 'New Members', FROM sites Link to comment https://forums.phpfreaks.com/topic/140249-solved-cannot-show-all-rows/#findComment-737364 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.