I have a database that contains contractor's licenses. Each license can have multiple renewals but for reporting purposes I am only interested in the current (newest) renewal for each license. The very simplified query below gives me the data I am looking for the license number and the newest annual renewal number for that record
SELECT license.licensenumber, MAX(licenseannualrenewal.licenseannualnumber)
FROM logosdb.dbo.license INNER JOIN logosdb.dbo.licenseannualrenewal ON license.licenseid = licenseannualrenewal.licenseid
GROUP BY license.licensenumber
My problem is I need to include other fields and other tables but when I add them it starts pulling in the multiple annual renewals again instead of just the newest renewal. How do I make sure it only looks at the MAX(licenseannualrenewal.licenseannualnumber) no matter what else I select? THANKS!
SELECT license.licensenumber, MAX(licenseannualrenewal.licenseannualnumber)
FROM logosdb.dbo.license INNER JOIN logosdb.dbo.licenseannualrenewal ON license.licenseid = licenseannualrenewal.licenseid
GROUP BY license.licensenumber
My problem is I need to include other fields and other tables but when I add them it starts pulling in the multiple annual renewals again instead of just the newest renewal. How do I make sure it only looks at the MAX(licenseannualrenewal.licenseannualnumber) no matter what else I select? THANKS!