You can re-write you query in below manner:
resources
| where type == "microsoft.compute/virtualmachines"
| join kind=inner (
ResourceContainers
| where type =~ 'microsoft.resources/subscriptions'
| project SubName=name, subscriptionId)
on subscriptionId
| project name, resourceGroup, subscriptionId, SubName
| summarize count() by name,SubName,resourceGroup
| where count_>1
this will give you Name, SubName,resourceGroup of duplicate VMs.
If it worked for you, just Accept this as an answer.