SQL Distinct Still returns duplicate values

All,

     I've written the following SQL query and despite the fact that I have DISTINCT in the query, it's still returning duplicate values for Full User Name and Name0 (which is the machine name.).  Can anyone see what i'm doing wrong here?  Please keep in mind i'm still a newbie when it comes to SQL.


SELECT DISTINCT v_R_User.Full_User_Name0, v_GS_LastSoftwareScan.LastScanDate, arp.TimeStamp, sys.Name0
FROM         v_R_System AS sys INNER JOIN
                      v_Add_Remove_Programs AS arp ON sys.ResourceID = arp.ResourceID INNER JOIN
                      v_FullCollectionMembership AS fcm ON sys.ResourceID = fcm.ResourceID INNER JOIN
                      v_GS_LastSoftwareScan ON sys.ResourceID = v_GS_LastSoftwareScan.ResourceID INNER JOIN
                      v_R_User ON sys.User_Name0 = v_R_User.User_Name0
WHERE     (arp.DisplayName0 = 'Microsoft Office Standard 2007') AND (fcm.CollectionID = 'SMS00001') AND (v_GS_LastSoftwareScan.LastScanDate >= DATEADD(dd, - 30, 
                      GETDATE()))
GROUP BY v_R_User.Full_User_Name0, v_GS_LastSoftwareScan.LastScanDate, arp.TimeStamp, sys.Name0

Open in new window

Xeif3rAsked:
Who is Participating?
 
ralmadaCommented:
something like this?
SELECT 
	v_R_User.Full_User_Name0, 
	max(v_GS_LastSoftwareScan.LastScanDate), 
	max(arp.TimeStamp), 
	sys.Name0
FROM         v_R_System AS sys 
INNER JOIN v_Add_Remove_Programs AS arp ON sys.ResourceID = arp.ResourceID 
INNER JOIN v_FullCollectionMembership AS fcm ON sys.ResourceID = fcm.ResourceID 
INNER JOIN v_GS_LastSoftwareScan ON sys.ResourceID = v_GS_LastSoftwareScan.ResourceID 
INNER JOIN v_R_User ON sys.User_Name0 = v_R_User.User_Name0

WHERE   (arp.DisplayName0 = 'Microsoft Office Standard 2007') AND 
	(fcm.CollectionID = 'SMS00001') AND 
	(v_GS_LastSoftwareScan.LastScanDate >= DATEADD(dd, - 30, GETDATE()))

GROUP BY v_R_User.Full_User_Name0, sys.Name0

Open in new window

0
 
gothamiteCommented:
DISTINCT means the distinct of all columns, so you will get duplicates in one column if you have different values in one or more of the other columns. In other words the distinctness is over the combination of all SELECTed columns.
0
 
Xeif3rAuthor Commented:
Wow!  Perfect!  What was I doing wrong?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.