SELECT (resource.RESOURCENAME) AS "Computer Name", count(sdatt.attachmentname) AS "Attachment Count", LONGTODATE(MAX(sdatt.attachedon)) "Last Document Attached on", (select sdattnew.attachmentname from sdeskattachment sdattnew where sdattnew.attachmentid = (select MAX(rattnew.attachmentid) from resourceattachment rattnew where rattnew.resourceid = resource.resourceid)) "Last Document Name" FROM Resources resource left join resourceattachment ratt on resource.resourceid = ratt.resourceid left join sdeskattachment sdatt on sdatt.attachmentid = ratt.attachmentid LEFT JOIN ComponentDefinition product ON resource.COMPONENTID = product.COMPONENTID LEFT JOIN ComponentType productType ON product.COMPONENTTYPEID = productType.COMPONENTTYPEID LEFT JOIN ResourceType rtype ON productType.RESOURCETYPEID = rtype.RESOURCETYPEID where rtype.type not like 'Software' group by resource.resourceid, resource.RESOURCENAME