Get records with max value for each group of grouped SQL results

How do you get the rows that contain the max value for each grouped set? I’ve seen some overly-complicated variations on this question, and none with a good answer. I’ve tried to put together the simplest possible example: Given a table like that below, with person, group, and age columns, how would you get the … Read more

SQL join: selecting the last records in a one-to-many relationship

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 one SELECT statement. What is the best practice? Any advice on building indexes? Please use these table/column names in your answer: customer: … Read more