Suppose I have a table of customers and a table of purchases. Each purchase belongs to one customer. I want to get a list of all customers along with their last purchase in
Try this, It will help.
I have used this in my project.
SELECT * FROM customer c OUTER APPLY(SELECT top 1 * FROM purchase pi WHERE pi.customer_id = c.Id order by pi.Id desc) AS [LastPurchasePrice]