I realize this is just like SQL/mysql - Select distinct/UNIQUE but return all columns? but I am at a total lose and it's always the way, report needed right away...
I am wanting to get (all from the same table)
First - Unique AsbestosNumber
Seconds - based on that the last survey date
Last - based on those filtered down results get the highest Risk (First look to see it is has 'A', then 'B' then 'C' then 'D' then anything else
select AsbestosUPRN, OverallRiskCategory, SurveyDate FROM TblAsbestos GROUP BY AsbestosUPRN, OverallRiskCategory, SurveyDate
but have also tried the below which ive of not be bound errors.
SELECT * FROM TblAsbestos
JOIN (SELECT AsbestosUPRN, Max(OverallRiskCategory) FROM TblAsbestos) As Tbl2
On Tbl2.AsbestosUPRN = Tbl1.AsbestosUPRN
ORDER BY Tbl1.AsbestosUPRN
I then need to modify the report to also search by a unique number in another table.
Example date:
AsbestosUPRN SurveyDate OverallRiskCategory
011203200 2014-01-07 00:00:00.000 N/A
011203200 2014-01-07 00:00:00.000 N/A
011203200 2014-01-07 00:00:00.000 N/A
011203200 2014-01-07 00:00:00.000 C
011203200 2014-01-07 00:00:00.000 N/A
011203200 2014-01-07 00:00:00.000 N/A
030700630 2014-01-10 00:00:00.000 N/A
030700630 2014-01-10 00:00:00.000 N/A
030700620 2014-01-15 00:00:00.000 N/A
030700620 2014-01-15 00:00:00.000 N/A
030700620 2014-01-15 00:00:00.000 N/A
030700620 2014-01-15 00:00:00.000 N/A
030700620 2014-01-15 00:00:00.000 N/A
030700630 2014-01-10 00:00:00.000 N/A
030700630 2014-01-10 00:00:00.000 N/A
Fixed, working code:
select
AsbestosUPRN,
min(OverallRiskCategory) as OverallRiskCategory,
max(SurveyDate) as SurveyDate
FROM TblAsbestos
GROUP BY
AsbestosUPRN