'How do I avoid duplicate rows in SQL none of the JOIN commands are working for the query
I recently created a query that list ARP for a computer & the drives mapped to the computer Everything comes back but the 2nd table is causing the 1st table to list duplicates. When it runs if the user has 4 network drives it lists the application 4 times, If the user has 5 drives it list the application 5 times & so on. My query is below along with the example output.
Query:
SELECT DISTINCT
v_Add_Remove_Programs_Alias.DisplayName0,
v_Add_Remove_Programs_Alias.Publisher0,
v_Add_Remove_Programs_Alias.Version0,
v_GS_MAPPEDDRIVES.mappedletter0,
v_GS_MAPPEDDRIVES.mappedname0,
v_GS_MAPPEDDRIVES.servername0,
v_GS_MAPPEDDRIVES.dateinventoried0
FROM fn_rbac_Add_Remove_Programs(@UserSIDs) v_Add_Remove_Programs_Alias
JOIN fn_rbac_R_System(@UserSIDs) v_R_System_Alias
ON v_Add_Remove_Programs_Alias.ResourceID = v_R_System_Alias.ResourceID
LEFT JOIN v_GS_MAPPEDDRIVES
ON v_R_System_Alias.ResourceID = v_GS_MAPPEDDRIVES.ResourceID
WHERE v_R_System_Alias.Netbios_Name0 = @computername
AND v_Add_Remove_Programs_Alias.DisplayName0 NOT LIKE %SOMEAPP%
ORDER BY v_Add_Remove_Programs_Alias.DisplayName0
Output:
| Display Name | Publisher | Drive | Server | Sharename | Date |
|---|---|---|---|---|---|
| Microsoft Word | Microsoft | A: | Servername1 | Share1 | Date |
| Microsoft Word | Microsoft | A: | Servername1 | Share1 | Date |
| Microsoft Word | Microsoft | A: | Servername1 | Share1 | Date |
| Microsoft ABC | Microsoft | B: | Servername2 | Share2 | Date |
| Microsoft ABC | Microsoft | B: | Servername2 | Share2 | Date |
| Microsoft ABC | Microsoft | B: | Servername2 | Share2 | Date |
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
