I have the following table:
create table ARDebitDetail(ID_ARDebitDetail int identity,
ID_Hearing int, ID_AdvancedRatePlan int)
I am trying to get the latest ID_AdvancedRatePlan based on a ID_Hearing. By latest I mean with the largest ID_ARDebitDetail. I have this query and it works fine.
select ID_AdvancedRatePlan
from ARDebitDetails
where ID_Hearing = 135878
and ID_ARDebitDetail =
( select max(ID_ARDebitDetail)
from ARDebitDetails
where ID_AdvancedRatePlan > 0 and ID_Hearing = 135878
)
However, it just looks ugly and smells bad. Is there a way to rewrite it in a more concise manner?