→ 🚀What's New? Join Us for the Fall Product Launch! Register Now !
‎07-29-2020 08:13 PM
‎07-29-2020 08:58 PM
Select Top 1000000
tblAssets.Userdomain,
tblAssets.Username,
tblAssets.AssetID,
tblAssets.AssetName,
tsysAssetTypes.AssetTypename,
tsysAssetTypes.AssetTypeIcon10 As icon,
tblAssets.IPAddress,
tblAssets.Lastseen,
tblAssets.Lasttried
From
tblAssets
Inner Join tblAssetCustom On tblAssets.AssetID = tblAssetCustom.AssetID
Inner Join tsysAssetTypes On tsysAssetTypes.AssetType = tblAssets.Assettype
Inner Join tblComputerSystem ON tblComputerSystem.AssetID = tblAssets.AssetID
Inner Join (SELECT
tblAssets.Userdomain,
tblAssets.Username,
Count(*) AS UserCount
FROM
tblAssets
Inner Join tblAssetCustom On tblAssets.AssetID = tblAssetCustom.AssetID
Inner Join tblComputerSystem ON tblComputerSystem.AssetID = tblAssets.AssetID
WHERE
tblAssetCustom.State = 1
AND tblComputerSystem.DomainRole < 2 -- non-servers
AND tblAssets.Userdomain IS NOT NULL
AND tblAssets.Username IS NOT NULL
GROUP BY
tblAssets.Userdomain,
tblAssets.Username) AS UserCount ON UserCount.UserDomain=tblAssets.UserDomain
AND UserCount.UserName=tblAssets.UserName
AND UserCount.UserCount > 1 -- only those logged into more than 1 machine
Where
tblAssetCustom.State = 1
And tblComputerSystem.DomainRole < 2 -- non-servers
Order By
tblAssets.Userdomain,
tblAssets.Username,
tblAssets.AssetName
‎07-30-2020 01:43 PM
RC62N wrote:
Give this a try:Select Top 1000000
tblAssets.Userdomain,
tblAssets.Username,
tblAssets.AssetID,
tblAssets.AssetName,
tsysAssetTypes.AssetTypename,
tsysAssetTypes.AssetTypeIcon10 As icon,
tblAssets.IPAddress,
tblAssets.Lastseen,
tblAssets.Lasttried
From
tblAssets
Inner Join tblAssetCustom On tblAssets.AssetID = tblAssetCustom.AssetID
Inner Join tsysAssetTypes On tsysAssetTypes.AssetType = tblAssets.Assettype
Inner Join tblComputerSystem ON tblComputerSystem.AssetID = tblAssets.AssetID
Inner Join (SELECT
tblAssets.Userdomain,
tblAssets.Username,
Count(*) AS UserCount
FROM
tblAssets
Inner Join tblAssetCustom On tblAssets.AssetID = tblAssetCustom.AssetID
Inner Join tblComputerSystem ON tblComputerSystem.AssetID = tblAssets.AssetID
WHERE
tblAssetCustom.State = 1
AND tblComputerSystem.DomainRole < 2 -- non-servers
AND tblAssets.Userdomain IS NOT NULL
AND tblAssets.Username IS NOT NULL
GROUP BY
tblAssets.Userdomain,
tblAssets.Username) AS UserCount ON UserCount.UserDomain=tblAssets.UserDomain
AND UserCount.UserName=tblAssets.UserName
AND UserCount.UserCount > 1 -- only those logged into more than 1 machine
Where
tblAssetCustom.State = 1
And tblComputerSystem.DomainRole < 2 -- non-servers
Order By
tblAssets.Userdomain,
tblAssets.Username,
tblAssets.AssetName
The sub-SELECT makes a list of domain/users last logged on to active non-servers.
The JOIN limits the list to only those logged on to more than one machine, and the fact that it's an INNER join limits the main selection to only members of that list.
Experience Lansweeper with your own data. Sign up now for a 14-day free trial.
Try Now