Note: I have browsed similar questions, but they didn't answer my question.
To practice SQL, I have created a testing database in MS Access. It stores information about a car shop's business. The layout is like so:
I wish to list (group by them) the car makes with the service that is most frequently bought/ordered for the given make. I don't know how to use the ORDER BY
clause here. SO: each make should only be shown once, with its most frequently purchased service.
Example:
Porsche | Oil change
Ford | Tire change
Chevrolet | Brake fluid change
etc.
I suppose I should somehow nest it, but I'm at a loss as to how to exactly do it.
I was able to build the following query, which will list all car-service relations:
SELECT cars.Make, services.[Service name]
FROM (repairs
INNER JOIN cars ON cars.[Car number] = repairs.[Car number])
INNER JOIN services ON services.ID = repairs.[Service ID]
GROUP BY cars.Make, services.[Service name];
How would I build this query properly, as described above?