I apologize for the poor subject/title, but I'm having a hard time verbalizing how to state my problem, so I'll draw it out with a (probably) lengthy example:I have a rather simple query that gets the number of sessions for a PC for a certain date range. Note at this point that the WHERE clause is commented out. What I'm hoping to receive is the full list of PCs, even those that have ZERO/NULL sessions during that range. However, when I add that WHERE clause I ONLY get the PCs that had sessions during that range. This is problematic because I can't see the PCs that were unused during that period. SELECT f_assetnetbiosname, COUNT(*) as 'Sessions' FROM tb_assets LEFT JOIN tb_sessions ss ON ss.f_computername = f_assetnetbiosname --WHERE f_sessiondate BETWEEN '04/01/2015' AND '04/30/2015' GROUP BY f_assetnetbiosname======================== ==================================|| tb_assets | | tb_sessions |======================== ==================================|| f_assetnetbiosname | | f_computername f_sessiondate |------------------------ ----------------------------------|| COMP_001 | | COMP_002 03/30/2015 || COMP_002 | | COMP_001 03/30/2015 || COMP_003 | | COMP_001 04/02/2015 |------------------------ | COMP_001 04/03/2015 | | COMP_001 04/04/2015 | | COMP_001 04/04/2015 | -----------------------------------
The query based on these results would return the following result set:|=================================|| f_assetnetbiosname | Sessions ||=================================|| COMP_001 | 5 || COMP_002 | 1 || COMP_003 | NULL ||=================================|
The problem is that I need to actually search only for a date range. So if I uncomment out the "WHERE" clause in the query above, the result set looks only like the following:|=================================|| f_assetnetbiosname | Sessions ||=================================|| COMP_001 | 4 ||=================================|
But I need it to look like the following:|=================================|| f_assetnetbiosname | Sessions ||=================================|| COMP_001 | 4 || COMP_002 | NULL || COMP_003 | NULL ||=================================|
Does anybody have a fix for this? Note that the example above is just that - an example. The real query is a multi-CTE bearcat but I figured it better to whittle this down to the basics so that I don't cloud the conversation by showing off my bad code :).Thanks in advance