Recently, I needed something “similar” to this post and wanted to share the technique. Suppose you have an Order and OrderDetail table, and you want to return information from the Order table along with the product name associated with the row with the highest price. Here you can pull it without subtexts, RANK, etc. The key is to create and aggregate, which combine the key and value from the detailed table, and then just max, and substitute the desired value.
create table CustOrder(ID int) create table CustOrderDetail(OrderID int, Price money, ProdName varchar(20)) insert into CustOrder(ID) values(1) insert into CustOrderDetail(OrderID,Price,ProdName) values(1,10,'AAA') insert into CustOrderDetail(OrderID,Price,ProdName) values(1,50,'BBB') insert into CustOrderDetail(OrderID,Price,ProdName) values(1,10,'CCC') select o.ID, JoinAggregate=max(convert(varchar,od.price)+'*'+od.prodName), maxProd= SUBSTRING( max(convert(varchar,od.price)+'*'+od.prodName) ,CHARINDEX('*',max(convert(varchar,od.price)+'*'+convert(varchar,od.prodName)) )+1,9999) from CustOrder o inner join CustOrderDetail od on od.orderID = o.ID group by o.ID

source share